Open In App

SASS | String Functions

Improve
Improve
Like Article
Like
Save
Share
Report

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 use 1 based indexing. It means the first character of the SASS string is 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:

CSS




quote(GeeksforGeeks);


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

CSS




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


  • Output: 
     
1

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

  • Example: 

CSS




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


  • Output: 
"GeeksforGeeks"

4. str-length($string) Function: This function returns the number of characters present in the given string. 

  • Example: 

CSS




str-length("GeeksforGeeks");


  • Output: 
13

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

  • Example: 

CSS




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


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

CSS




to-upper-case("geeksforgeeks");


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

CSS




to-lower-case("GEEKSFORGEEKS")


  • Output: 
     
"geeksforgeeks"

8. unique-id() Function: This function returns a randomly-generated unquoted string that is a valid CSS identifier. 

  • Example: 

CSS




unique-id();


  • Output: 
Randomly Generated ID

9. unquote($string) Function: This function returns the quoted string in unquoted format. 

  • Example: 

CSS




unquote("GeeksforGeeks")


  • Output: 
GeeksforGeeks

 



Last Updated : 08 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads