Skip to content
Related Articles

Related Articles

SASS sass:string Module
  • Last Updated : 21 Aug, 2020

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.

  • Syntax:
    string.to-upper-case(string)
    to-upper-case(string)
  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    @debug string.to-upper-case("Geeks For Geeks"); 
    @debug string.to-upper-case(geeks for geeks); 

    chevron_right

    
    

  • Output:
    "GEEKS FOR GEEKS"
    GEEKS FOR GEEKS
    
    • 7. string.to-lower-case() function: This function returns the copy of the given string with the ASCII letters converted to lower case.

      • Syntax:
        string.to-lower-case(string)
        to-lower-case(string)
      • Example:
        filter_none

        edit
        close

        play_arrow

        link
        brightness_4
        code

        @debug string.to-lower-case("Geeks For Geeks"); 
        @debug string.to-lower-case(geeks for geeks); 

        chevron_right

        
        

      • Output:
        "geeks for geeks"
        geeks for geeks
        

      8. string.unique-id() function: This function returns a randomly-generated string that is a valid CSS identifier and unique within the current Sass compilation.

      • Syntax:
        string.unique-id()
        unique-id()
      • Example:
        filter_none

        edit
        close

        play_arrow

        link
        brightness_4
        code

        @debug string.unique-id();  
        @debug string.unique-id(); 

        chevron_right

        
        

      • Output:
        uabtrnzug
        u6w1b1def
        

      9. string.unquote() function: This function returns the given string as an unquoted string. This function can produce strings that are not valid CSS, so this function must be used carefully.

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

        edit
        close

        play_arrow

        link
        brightness_4
        code

        @debug string.unquote(GeeksForGeeks);
        @debug string.unquote(".color: green");

        chevron_right

        
        

      • Output:
        GeeksForGeeks
        .color: green
        
      My Personal Notes arrow_drop_up
Recommended Articles
Page :