SASS | String Functions

SASS string functions are quite similar to the string functions of any other programming language with only a single difference i.e. the SASS strings uses 1 based indexing. It means the first character of the SASS string stored at index 1 (not 0).

We have created a table that contains the list of all SASS functions with a brief description and examples.

  1. quote($string) Function: This function adds the quotes to the unquoted string and returns the quoted string.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      quote(GeeksforGeeks);

      chevron_right

      
      

    • Output:
      "GeeksforGeeks"
  2. str-index($string, $substring) Function: This function returns the index of first occurrence of the substring in a given string. If the string does not contain substring then it returns null.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      str-index("Geeksforgeeks", "G");

      chevron_right

      
      

    • Output:
      1
  3. str-insert($string, $insert, $index) Function: This function returns a copy of given string with inserted string at given index.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      str-insert("forGeeks", "Geeks", 0);

      chevron_right

      
      

    • Output:
      "GeeksforGeeks"
  4. str-length($string) Function: This function returns the number of characters preent in the given string.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      str-length("GeeksforGeeks");

      chevron_right

      
      

    • Output:
      13
  5. str-slice($string, $start-at, $end-at: -1) Function: This function returns the slice of string between the strart and end index (both inclusive).
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      str-slice("GeeksforGeeks", 8);
      str-slice("GeeksforGeeks", 6, 8);

      chevron_right

      
      

    • Output:
      "Geeks"
      for
  6. to-upper-case($string) Function: This function returns a copy of given string with the ASCII letters converted into upper case.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      to-upper-case("geeksforgeeks");

      chevron_right

      
      

    • Output:
      "GEEKSFORGEEKS"
  7. to-lower-case($string) Function: This function returns a copy of given string with the ASCII letters converted into lower case.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      to-lower-case("GEEKSFORGEEKS")

      chevron_right

      
      

    • Output:
      "geeksforgeeks"
  8. unique-id() Function: This function returns a randomly-generated unquoted string that is a valid CSS identifier.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      unique-id();

      chevron_right

      
      

    • Output:
      Randomely Generated ID
  9. unquote($string) Function: This function returns the quoted string in unquoted format.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      unquote("GeeksforGeeks")

      chevron_right

      
      

    • Output:
      GeeksforGeeks



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.