SASS sass:string Module

The sass:string module makes it easy to combine, search, or split strings apart. The following are the list of functions that can be used using this module.

1. string.quote() function: This function returns a quoted string.

  • Syntax:
    string.quote(string)
    quote(string)
  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    @debug string.quote(GeeksForGeeks);
    @debug string.quote("GeeksForGeeks");

    chevron_right

    
    

  • Output:
    "GeeksForGeeks"
    "GeeksForGeeks"
    

2. string.index() function: This function returns the first index of the substring of a string, or null if the string does not contain the given substring.

  • Syntax:
    string.index(string, substring)
    str-index(string, substring)
  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    @debug string.index("Geeks For Geeks", "Geeks"); 
    @debug string.index("Geeks For Geeks", "For");

    chevron_right

    
    

  • Output:
    1
    7
    

3. string.insert() function: This function returns a copy of string with the given insert substring inserted at the given index.

  • Syntax:
    string.insert(string, insert, index)
    str-insert(string, insert, index)

    If the given index is higher than the length of string, the insert substring is added at the end of the string. If the index is smaller than the negative length of the string, then the insert substring is added to the start of the string.

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    @debug string.insert("Geeks Geeks", " For", 7); 
    @debug string.insert("Geeks Geeks", " For", -7);

    chevron_right

    
    

  • Output:
    "Geeks For Geeks"
    "Geeks For Geeks"
    

4. string.length() function: This function returns the total number of characters of the given string.



  • Syntax:
    string.length(string)
    str-length(string)
  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    @debug string.length("Geeks For Geeks"); 
    @debug string.length(GFG); 
    @debug string.index("");

    chevron_right

    
    

  • Output:
    15
    3
    0
    

5. string.slice() function: This function returns the slice of string starting at index given as “start-at” and ending at index given as “end-at” (both including).

  • Syntax:
    string.slice(string, start-at, end-at: -1)
    str-slice(string, start-at, end-at: -1)
  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    @debug string.slice("Geeks For Geeks", 6); 
    @debug string.slice("Geeks For Geeks", 1, 5); 
    @debug string.slice("Geeks For Geeks", 1, -7);

    chevron_right

    
    

  • Output:
    For Geeks
    Geeks
    Geeks For
    

6. string.to-upper-case() function: This function returns the copy of the given string with the ASCII letters converted to upper case.