Sass String Functions
Sass String Functions are used to manipulate strings and obtain related information.
The starting index value for Sass strings is 1, not 0.
The following table lists the Sass string functions:
Function | Description & Example |
---|---|
quote(string) | Adds quotes to the string. <br> <br> Example: <br>quote(tutorialpro) <br>Result: "tutorialpro" |
str-index(string, substring) | Returns the position of the first occurrence of substring in string. Returns null if no match is found. <br> <br> str-index(abcd, a) => 1<br>str-index(abcd, ab) => 1<br>str-index(abcd, X) => null<br>str-index(abcd, c) => 3 |
str-insert(string, insert, index) | Inserts insert into string at the specified index. <br> <br> Example: <br>str-insert("Hello world!", " tutorialpro", 6) <br>Result: "Hello <br> tutorialpro world!" |
str-length(string) | Returns the length of the string. <br> <br> Example: <br>str-length("tutorialpro") <br>Result: 6 |
str-slice(string, start, end) | Extracts a substring from string, setting the start and end positions with start-at and end-at. If the end index is not specified, it defaults to the end of the string. <br> <br> str-slice("abcd", 2, 3) => "bc"<br>str-slice("abcd", 2) => "bcd"<br>str-slice("abcd", -3, -2) => "bc"<br>str-slice("abcd", 2, -2) => "bc" |
to-lower-case(string) | Converts the string to lowercase. <br> <br> Example: <br>to-lower-case("tutorialpro") <br>Result: "tutorialpro" |
to-upper-case(string) | Converts the string to uppercase. <br> <br> Example: <br>to-upper-case("tutorialpro") <br>Result: "tutorialpro" |
unique-id() | Returns a random unquoted string as an id. This ensures uniqueness only within a single Sass compilation. <br> <br> Example: <br>unique-id() <br>Result: <br> uad053b1c |
unquote(string) | Removes quotes from the string. <br> <br> Example: <br>unquote("tutorialpro") <br>Result: tutorialpro |