---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideStringUtil - Scoped, Global

# GlideStringUtil - Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 4 minutes to read

The GlideStringUtil API provides string handling methods.

Access these methods using the static object GlideStringUtil. This class is available in scoped and global scripts.

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

Replaces periods with underscore characters.
{#GSUS-dotToUnderBar_S__table_vvg_gbv_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | Text to process. |
[Table 1. Parameters]

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

| Type | Description |
|-|-|
| String | Text with periods replaced with underscores. |
[Table 2. Returns]

{#GSUS-dotToUnderBar_S__table_wvg_gbv_5cb}  

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

Output:

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

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

Removes quotes from a string.
{#GSUS-escapeAllQuotes_S__table_pyk_bd4_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | The string to be processed. |
[Table 3. Parameters]

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

| Type | Description |
|-|-|
| String | The string with quotes removed. |
[Table 4. Returns]

{#GSUS-escapeAllQuotes_S__table_qyk_bd4_5cb}  

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

Output:

    lets escape some quotes

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

Replaces problem characters with escape characters.
{#GSUS-escapeForHomePage_S__table_r25_cgv_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | Text to process. |
[Table 5. Parameters]

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

| Type | Description |
|-|-|
| String | Text with problem characters replaced with escape characters. |
[Table 6. Returns]

{#GSUS-escapeForHomePage_S__table_s25_cgv_5cb}  

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

Output:

    %3ctest%3e string \n to escape

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

Replaces illegal characters with their escape codes.
Using this method removes illegal characters that might cause the UI to render improperly,
or trigger a client side attack such as JavaScript or HTML injection.
{#GSUS-escapeHTML_S__table_mtt_fym_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| htmlString | String | Text to process. |
[Table 7. Parameters]

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

| Type | Description |
|-|-|
| String | Text with illegal characters replaced with their escape codes. |
[Table 8. Returns]

{#GSUS-escapeHTML_S__table_ntt_fym_5cb}  

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

Output:

    &quot;&lt;&gt;&amp;

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

Replaces non-printable characters with their printable notation.
{#GSUS-escapeNonPrintable_S__table_qm1_f1v_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | Text to process. |
[Table 9. Parameters]

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

| Type | Description |
|-|-|
| String | Text with non-printable characters replaced with printable notation. |
[Table 10. Returns]

{#GSUS-escapeNonPrintable_S__table_rm1_f1v_5cb}  

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

Output:

    test \t non \u0000 printable \u0007 chars

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

Replaces query term separators "\^" with their escape sequence "\^\^".
{#GSUS-escapeQTermSeparator_S__table_zwy_fdv_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | Text to process. |
[Table 11. Parameters]

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

| Type | Description |
|-|-|
| String | Text with query term separators replaced with the escape characters. |
[Table 12. Returns]

{#GSUS-escapeQTermSeparator_S__table_axy_fdv_5cb}  

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

Output:

    test^^Test

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

Replaces quotes with escape characters by adding a backslash before each
quote.
{#GSUS-escapeTicks_S__table_ixz_zd4_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | Text to process. |
[Table 13. Parameters]

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

| Type | Description |
|-|-|
| String | Text with backslashes added before quotes. |
[Table 14. Returns]

{#GSUS-escapeTicks_S__table_jxz_zd4_5cb}  

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

Output:

    let\'s try escapeTicks

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

Replaces illegal HTML characters into HTML notation.
Using this method removes illegal characters that might cause the UI to render improperly,
or trigger a client side attack such as JavaScript or HTML injection.
{#GSUS-getHTMLValue_S__table_bbb_q14_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | Text to process. |
[Table 15. Parameters]

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

| Type | Description |
|-|-|
| String | Text with illegal characters replaced with HTML notation. |
[Table 16. Returns]

{#GSUS-getHTMLValue_S__table_cbb_q14_5cb}  

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

Output:

    &amp;

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

Extracts numeric characters from a string.
{#GSUS-getNumeric_S__table_wzj_yb4_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | Text to process. |
[Table 17. Parameters]

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

| Type | Description |
|-|-|
| String | Text containing only numeric characters. |
[Table 18. Returns]

{#GSUS-getNumeric_S__table_xzj_yb4_5cb}  

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

Output:

    123456789

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

Validates whether the specified string is a valid base64 string.
{#GSUS-isBase64_S__table_xzl_h3v_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | Text to process. |
[Table 19. Parameters]

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

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the specified string is in valid base64 format. Possible values: * true: Valid base64 formatted string. * false: Invalid base64 formatted string. {#GSUS-isBase64_S__ul_npg_wwp_3pb} |
[Table 20. Returns]

{#GSUS-isBase64_S__table_yzl_h3v_5cb}  

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

Output:

    false

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

Validates whether the specified string is in valid sys_id format.
The sys_id format is a sequence of 32 hexadecimal characters where all the characters are
in the range \[0-9, a-f, A-F\].
{#GSUS-isEligibleSysID_S__table_cgh_2jv_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | Text to process. |
[Table 21. Parameters]

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

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the specified string is in valid sys_id format. Possible values: * true: Valid sys_id formatted string. * false: Invalid sys_id formatted string. {#GSUS-isEligibleSysID_S__ul_npg_wwp_3pb} |
[Table 22. Returns]

{#GSUS-isEligibleSysID_S__table_dgh_2jv_5cb}  

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

Output:

    true

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

Replaces the new line character, `/n`, with a break code,
`<br/>`.
{#GSUS-newLinesToBreaks_S__table_mty_zn4_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | Text to process. |
[Table 23. Parameters]

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

| Type | Description |
|-|-|
| String | Text with new line characters replaced with HTML break code. |
[Table 24. Returns]

{#GSUS-newLinesToBreaks_S__table_nty_zn4_5cb}  

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

Output:

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

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

Replaces carriage returns, line feeds, and tabs with spaces, and then removes leading,
trailing, and duplicate spaces.
{#GSUS-normalizeWhitespace_S__table_xdj_yy5_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceString | String | Text to process. |
[Table 25. Parameters]

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

| Type | Description |
|-|-|
| String | Text with carriage returns, line feeds, and tabs replaced with spaces, and then leading, trailing, and duplicate spaces removed. |
[Table 26. Returns]

{#GSUS-normalizeWhitespace_S__table_ydj_yy5_5cb}  

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

Output:

    test with (new line) and (tabulation)

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

Replaces escape characters with their respective character.
This method replaces these escape characters: `&lt; &gt: &nbsp;
&amp; &quote;`.  
Note:  
In scoped applications call this method as unescapeHTML(String). In global applications call this method as unEscapeHTML(String).
{#GSUS-unescapeHTML_S__table_uzm_zzm_5cb__entry__3}

| Name | Type | Description |
|-|-|-|
| htmlString | String | String to process. |
[Table 27. Parameters]

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

| Type | Description |
|-|-|
| String | String with the escape characters replaced. |
[Table 28. Returns]

{#GSUS-unescapeHTML_S__table_vzm_zzm_5cb}  
This code example shows the method being called in a global application.

    mydata='&quot;&lt;&gt;&amp;';
    unescaped=GlideStringUtil.unEscapeHTML(mydata);
    gs.info(unescaped);

Output:

    "<>&

This code example shows the method being called in a scoped application.

    mydata='&quot;&lt;&gt;&amp;';
    unescaped=GlideStringUtil.unescapeHTML(mydata);
    gs.info(unescaped);

Output:

    "<>&

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

Encodes non-ASCII characters, unsafe ASCII characters, and spaces so you can use the returned string on the Internet. Uses UTF-8 encoding. Uses percent (%) encoding.
Note:  
Only available in global scope.
{#GSUS-urlEncode_S__table_bcw_xvt_lyb__entry__3}

| Name | Type | Description |
|-|-|-|
| url | String | String to encode. |
[Table 29. Parameters]

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

| Type | Description |
|-|-|
| String | String with non-ASCII characters, unsafe ASCII characters, and spaces encoded. |
[Table 30. Returns]

{#GSUS-urlEncode_S__table_ccw_xvt_lyb}  

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

Output:

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


