Sass String Functions
Sass String functions are used to handle strings and obtain related information.
The starting index value of Sass strings starts from 1, remember it is not 0.
The following table lists Sass string functions:
| Function | Description & Example |
|---|---|
| quote(string) | Add quotes to a string. Example: quote(example) Result: "example" |
| str-index(string, substring) | Returns the position of the first occurrence of substring in string. Returns null if no match is found for the substring.str-index(abcd, a) => 1 str-index(abcd, ab) => 1 str-index(abcd, X) => null str-index(abcd, c) => 3 |
| str-insert(string, insert, index) | Insert insert at the index position in string. Example: str-insert("Hello world!", " example", 6) Result: "Hello example world!" |
| str-length(string) | Returns the length of the string. Example: str-length("example") Result: 6 |
| str-slice(string, start, end) | Extract 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.
str-slice("abcd", 2, 3) => "bc"
str-slice("abcd", 2) => "bcd"
str-slice("abcd", -3, -2) => "bc"
str-slice("abcd", 2, -2) => "bc"
|
| to-lower-case(string) | Convert string to lowercase Example: to-lower-case("EXAMPLE") Result: "example" |
| to-upper-case(string) | Convert string to uppercase Example: to-upper-case("example") Result: "EXAMPLE" |
| unique-id() | Returns a random unquoted string as an id. However, it can only guarantee that this id is unique within a single Sass compilation. Example: unique-id() Result: uad053b1c |
| unquote(string) | Remove quotes from a string Example: unquote("example") Result: example |
Other Extensions
Sass Functions