---
sourceDocument: Référence de l’API Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/fr-FR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - fr-FR

ft:publication_title :

    - Référence de l’API Xanadu

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideStringUtil : champ d'application, global

# GlideStringUtil : champ d'application, global {#ariaid-title1}

* Rversion finale: Xanadu
* 
* Mis à jour 1 août 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 5 minutes de lecture

L'API GlideStringUtil fournit des méthodes de gestion des chaînes.

Accédez à ces méthodes à l'aide de l'objet statique GlideStringUtil. Cette classe est disponible dans les scripts étendus et globaux.

## GlideStringUtil : dotToUnderBar(String sourceString) {#ariaid-title2}

Remplace les points par des traits de soulignement.
{#GSUS-dotToUnderBar_S__table_vvg_gbv_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Texte à traiter. |
[Tableau 1. Paramètres]

{#GSUS-dotToUnderBar_S__table_vvg_gbv_5cb} {#GSUS-dotToUnderBar_S__table_wvg_gbv_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Le texte avec des points a été remplacé par des traits de soulignement. |
[Tableau 2. Renvoie]

{#GSUS-dotToUnderBar_S__table_wvg_gbv_5cb}  

    var filename="../../../../../../etc/passwd";
    cleanFilename=GlideStringUtil.dotToUnderBar(filename);
    gs.info(cleanFilename);

Sortie :

     __/__/__/__/__/__/etc/passwd

## GlideStringUtil : escapeAllQuotes(String sourceString) {#ariaid-title3}

Supprime les guillemets d'une chaîne.
{#GSUS-escapeAllQuotes_S__table_pyk_bd4_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Chaîne à traiter. |
[Tableau 3. Paramètres]

{#GSUS-escapeAllQuotes_S__table_pyk_bd4_5cb} {#GSUS-escapeAllQuotes_S__table_qyk_bd4_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Chaîne avec guillemets supprimés. |
[Tableau 4. Renvoie]

{#GSUS-escapeAllQuotes_S__table_qyk_bd4_5cb}  

    mystring="let's escape some quotes";
    escapeQuote=GlideStringUtil.escapeAllQuotes(mystring);
    gs.info(escapeQuote);

Sortie :

    lets escape some quotes

## GlideStringUtil : escapeForHomePage(String sourceString) {#ariaid-title4}

Remplace les caractères problématiques par des caractères d'échappement.
{#GSUS-escapeForHomePage_S__table_r25_cgv_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Texte à traiter. |
[Tableau 5. Paramètres]

{#GSUS-escapeForHomePage_S__table_r25_cgv_5cb} {#GSUS-escapeForHomePage_S__table_s25_cgv_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Le texte comportant des caractères problématiques a été remplacé par des caractères d'échappement. |
[Tableau 6. Renvoie]

{#GSUS-escapeForHomePage_S__table_s25_cgv_5cb}  

    mystring="<test> string \n to escape";
    escapedString=GlideStringUtil.escapeForHomePage(mystring);
    gs.info(escapedString);

Sortie :

    %3ctest%3e string \n to escape

## GlideStringUtil : escapeHTML(String htmlString) {#ariaid-title5}

Remplace les caractères illégaux par leurs codes d'échappement.
Cette méthode supprime les caractères illégaux susceptibles d'entraîner un mauvais rendu de l'interface utilisateur ou de déclencher une attaque côté client telle que JavaScript ou une injection HTML.
{#GSUS-escapeHTML_S__table_mtt_fym_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Chaîne HTML | Chaîne | Texte à traiter. |
[Tableau 7. Paramètres]

{#GSUS-escapeHTML_S__table_mtt_fym_5cb} {#GSUS-escapeHTML_S__table_ntt_fym_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Le texte contenant des caractères illégaux a été remplacé par leur code d'échappement. |
[Tableau 8. Renvoie]

{#GSUS-escapeHTML_S__table_ntt_fym_5cb}  

    mydata='"<>&';
    mydata=GlideStringUtil.escapeHTML(mydata);
    gs.info(mydata);

Sortie :

    "<>&

## GlideStringUtil : escapeNonPrintable(String sourceString) {#ariaid-title6}

Remplace les caractères non imprimables par leur notation imprimable.
{#GSUS-escapeNonPrintable_S__table_qm1_f1v_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Texte à traiter. |
[Tableau 9. Paramètres]

{#GSUS-escapeNonPrintable_S__table_qm1_f1v_5cb} {#GSUS-escapeNonPrintable_S__table_rm1_f1v_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Le texte avec des caractères non imprimables est remplacé par une notation imprimable. |
[Tableau 10. Renvoie]

{#GSUS-escapeNonPrintable_S__table_rm1_f1v_5cb}  

    mystring="test \x09 non \x00 printable \x07 chars";
    escapedString=GlideStringUtil.escapeNonPrintable(mystring);
    gs.info(escapedString);

Sortie :

    test \t non \u0000 printable \u0007 chars

## GlideStringUtil : escapeQueryTermSeparator(String sourceString) {#ariaid-title7}

Remplace les séparateurs de termes de requête \<\< \^ \>\> par leur séquence d'échappement \<\< \^\^ \>\>.
{#GSUS-escapeQTermSeparator_S__table_zwy_fdv_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Texte à traiter. |
[Tableau 11. Paramètres]

{#GSUS-escapeQTermSeparator_S__table_zwy_fdv_5cb} {#GSUS-escapeQTermSeparator_S__table_axy_fdv_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Le texte contenant des séparateurs de termes de requête a été remplacé par des caractères d'échappement. |
[Tableau 12. Renvoie]

{#GSUS-escapeQTermSeparator_S__table_axy_fdv_5cb}  

    myquery="test^Test";
    escapedQuery=GlideStringUtil.escapeQueryTermSeparator(myquery);
    gs.info(escapedQuery);

Sortie :

    test^^Test

## GlideStringUtil : escapeTicks(String sourceString) {#ariaid-title8}

Remplace les guillemets par des caractères d'échappement en ajoutant une barre oblique inverse avant chaque guillemet.
{#GSUS-escapeTicks_S__table_ixz_zd4_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Texte à traiter. |
[Tableau 13. Paramètres]

{#GSUS-escapeTicks_S__table_ixz_zd4_5cb} {#GSUS-escapeTicks_S__table_jxz_zd4_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Texte avec barres obliques inverses ajoutées avant les guillemets. |
[Tableau 14. Renvoie]

{#GSUS-escapeTicks_S__table_jxz_zd4_5cb}  

    mystring="let's try escapeTicks";
    escaped=GlideStringUtil.escapeTicks(mystring);
    gs.info(escaped); 

Sortie :

    let\'s try escapeTicks

## GlideStringUtil : getHTMLValue(String sourceString) {#ariaid-title9}

Remplace les caractères HTML illégaux dans la notation HTML.
Cette méthode supprime les caractères illégaux susceptibles d'entraîner un mauvais rendu de l'interface utilisateur ou de déclencher une attaque côté client telle que JavaScript ou une injection HTML.
{#GSUS-getHTMLValue_S__table_bbb_q14_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Texte à traiter. |
[Tableau 15. Paramètres]

{#GSUS-getHTMLValue_S__table_bbb_q14_5cb} {#GSUS-getHTMLValue_S__table_cbb_q14_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Le texte contenant des caractères illégaux est remplacé par une notation HTML. |
[Tableau 16. Renvoie]

{#GSUS-getHTMLValue_S__table_cbb_q14_5cb}  

    mydata='&';
    htmlvalue=GlideStringUtil.getHTMLValue(mydata);
    gs.info(htmlvalue);

Sortie :

    &

## GlideStringUtil : getNumeric(String sourceString) {#ariaid-title10}

Extrait les caractères numériques d'une chaîne.
{#GSUS-getNumeric_S__table_wzj_yb4_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Texte à traiter. |
[Tableau 17. Paramètres]

{#GSUS-getNumeric_S__table_wzj_yb4_5cb} {#GSUS-getNumeric_S__table_xzj_yb4_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Texte ne contenant que des chiffres. |
[Tableau 18. Renvoie]

{#GSUS-getNumeric_S__table_xzj_yb4_5cb}  

    mystring='123 test 456 String 789 cleaning';
    onlyNumeric=GlideStringUtil.getNumeric(mystring);
    gs.info(onlyNumeric); 

Sortie :

    123456789

## GlideStringUtil : isBase64(String sourceString) {#ariaid-title11}

Valide si la chaîne spécifiée est une chaîne base64 valide.
{#GSUS-isBase64_S__table_xzl_h3v_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Texte à traiter. |
[Tableau 19. Paramètres]

{#GSUS-isBase64_S__table_xzl_h3v_5cb} {#GSUS-isBase64_S__table_yzl_h3v_5cb__entry__2}

| Type | Description |
|-|-|
| Booléen | Marqueur indiquant si la chaîne spécifiée est au format base64 valide. Valeurs possibles : * vrai : chaîne formatée base64 valide. * false : chaîne formatée base64 non valide. {#GSUS-isBase64_S__ul_npg_wwp_3pb} |
[Tableau 20. Renvoie]

{#GSUS-isBase64_S__table_yzl_h3v_5cb}  

    //(adding a "*" to corrupt the base64 format)
    base64="GethdTYehdtshetB*";
    isValid=GlideStringUtil.isBase64(base64);
    gs.info(isValid);

Sortie :

    false

## GlideStringUtil : isEligibleSysID(String sourceString) {#ariaid-title12}

Valide si la chaîne spécifiée est au format sys_id valide.
Le format sys_id est une séquence de 32 caractères hexadécimaux où tous les caractères sont dans la plage \[0-9, a-f, A-F\].
{#GSUS-isEligibleSysID_S__table_cgh_2jv_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Texte à traiter. |
[Tableau 21. Paramètres]

{#GSUS-isEligibleSysID_S__table_cgh_2jv_5cb} {#GSUS-isEligibleSysID_S__table_dgh_2jv_5cb__entry__2}

| Type | Description |
|-|-|
| Booléen | Marqueur indiquant si la chaîne spécifiée est au format sys_id valide. Valeurs possibles : * vrai : valide sys_id chaîne formatée. * false : chaîne formatée sys_id non valide. {#GSUS-isEligibleSysID_S__ul_npg_wwp_3pb} |
[Tableau 22. Renvoie]

{#GSUS-isEligibleSysID_S__table_dgh_2jv_5cb}  

    sysID="62826bf03710200044e0bfc8bcbe5df1";
    isElig=GlideStringUtil.isEligibleSysID(sysID);
    gs.info(isElig);

Sortie :

    true

## GlideStringUtil : newLinesToBreaks(String sourceString) {#ariaid-title13}

Remplace le nouveau caractère de ligne, `/n`, par un code de coupure, `<br/>`.
{#GSUS-newLinesToBreaks_S__table_mty_zn4_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Texte à traiter. |
[Tableau 23. Paramètres]

{#GSUS-newLinesToBreaks_S__table_mty_zn4_5cb} {#GSUS-newLinesToBreaks_S__table_nty_zn4_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Le texte avec des caractères de nouvelle ligne est remplacé par un code de rupture HTML. |
[Tableau 24. Renvoie]

{#GSUS-newLinesToBreaks_S__table_nty_zn4_5cb}  

    mystring="new line break \n, this is after the break";
    replaceNewLine=GlideStringUtil.newLinesToBreaks(mystring);
    gs.info(replaceNewLine); 

Sortie :

    new line break <br/>, this is after the break

## GlideStringUtil : normalizeWhitespace(String sourceString) {#ariaid-title14}

Remplace les retours chariot, les sauts de ligne et les tabulations par des espaces, puis supprime les espaces de début, de fin et de doublon.
{#GSUS-normalizeWhitespace_S__table_xdj_yy5_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceString (en anglais seulement) | Chaîne | Texte à traiter. |
[Tableau 25. Paramètres]

{#GSUS-normalizeWhitespace_S__table_xdj_yy5_5cb} {#GSUS-normalizeWhitespace_S__table_ydj_yy5_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Le texte avec des retours chariot, des sauts de ligne et des tabulations a été remplacé par des espaces, puis les espaces de début, de fin et de doublon ont été supprimés. |
[Tableau 26. Renvoie]

{#GSUS-normalizeWhitespace_S__table_ydj_yy5_5cb}  

    mystring="test with \n (new line) and \t (tabulation)";
    normalizedString=GlideStringUtil.normalizeWhitespace(mystring);
    gs.info(normalizedString);

Sortie :

    test with (new line) and (tabulation)

## GlideStringUtil - unEscapeHTML(String htmlString) {#ariaid-title15}

Remplace les caractères d'échappement par leur caractère respectif.
Cette méthode remplace les caractères d'échappement suivants : `< > & & &quote ;`.  
Remarque :  
Dans les applications incluses dans le périmètre, appelez cette méthode en tant que unescapeHTML(String). Dans les applications globales, appelez cette méthode en tant que unEscapeHTML(String).
{#GSUS-unescapeHTML_S__table_uzm_zzm_5cb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Chaîne HTML | Chaîne | Chaîne à traiter. |
[Tableau 27. Paramètres]

{#GSUS-unescapeHTML_S__table_uzm_zzm_5cb} {#GSUS-unescapeHTML_S__table_vzm_zzm_5cb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Chaîne avec les caractères d'échappement remplacés. |
[Tableau 28. Renvoie]

{#GSUS-unescapeHTML_S__table_vzm_zzm_5cb}  
Cet exemple de code montre la méthode appelée dans une application globale.

    mydata='"<>&';
    unescaped=GlideStringUtil.unEscapeHTML(mydata);
    gs.info(unescaped);

Sortie :

    "<>&

Cet exemple de code montre la méthode appelée dans une application incluse dans le périmètre.

    mydata='"<>&';
    unescaped=GlideStringUtil.unescapeHTML(mydata);
    gs.info(unescaped);

Sortie :

    "<>&

## GlideStringUtil : urlEncode(String url) {#ariaid-title16}

Encode les caractères non-ASCII, les caractères ASCII non sécurisés et les espaces afin que vous puissiez utiliser la chaîne renvoyée sur Internet. Utilise l'encodage UTF-8. Utilise l'encodage de pourcentage (%).
Remarque :  
Disponible uniquement dans le champ d'application global.
{#GSUS-urlEncode_S__table_bcw_xvt_lyb__entry__3}

| Nom | Type | Description |
|-|-|-|
| URL | Chaîne | Chaîne à coder. |
[Tableau 29. Paramètres]

{#GSUS-urlEncode_S__table_bcw_xvt_lyb} {#GSUS-urlEncode_S__table_ccw_xvt_lyb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Chaîne avec des caractères non ASCII, des caractères ASCII non sécurisés et des espaces codés. |
[Tableau 30. Renvoie]

{#GSUS-urlEncode_S__table_ccw_xvt_lyb}  

    var mystring='Test characters: " < > & " < > &';
    escapedString=GlideStringUtil.urlEncode(mystring);
    gs.info(escapedString);

Sortie :

    Test+characters%3A+%22+%3C+%3E+%26+%26quot%3B+%26lt%3B+%26gt%3B+%26amp%3B


