Open In App

SASS sass:string Module

Improve
Improve
Like Article
Like
Save
Share
Report

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:




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

    
    

  • 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:




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

    
    

  • 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:




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

    
    

  • 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:




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

    
    

  • 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:




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

    
    

  • 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:




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

    
    

  • 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:




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

        
        

      • 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:




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

        
        

      • 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:




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

        
        

      • Output:
        GeeksForGeeks
        .color: green
        


      Last Updated : 21 Aug, 2020
      Like Article
      Save Article
      Previous
      Next
      Share your thoughts in the comments
Similar Reads