Understanding Sass String Functions
Sass String Functions Sass provides a variety of string functions that are essential for string manipulation and analysis. It is important to note that Sass strings are indexed...
Sass String Functions
Sass provides a variety of string functions that are essential for string manipulation and analysis. It is important to note that Sass strings are indexed starting from 1, meaning the first character of a string is at index 1. Below is a detailed overview of the available string functions in Sass:
| Function | Description & Example |
|-------------------|---------------------------------------------------------------------------------------|
| quote(string) | Surrounds the given string with quotes and returns the result.
Example: quote(Hello world!)
Result: "Hello world!" |
| str-index(string, substring) | Finds the index of the first occurrence of substring within string.
Example: str-index("Hello world!", "H")
Result: 1 |
| str-insert(string, insert, index) | Inserts insert into string at the specified index.
Example: str-insert("Hello world!", " wonderful", 6)
Result: "Hello wonderful world!" |
| str-length(string) | Computes the length of string in characters.
Example: str-length("Hello world!")
Result: 12 |
| str-slice(string, start, end) | Extracts a substring from string, starting at start and ending at end.
Example: str-slice("Hello world!", 2, 5)
Result: "ello" |
| to-lower-case(string) | Converts all characters in string to lower case.
Example: to-lower-case("Hello World!")
Result: "hello world!" |
| to-upper-case(string) | Converts all characters in string to upper case.
Example: to-upper-case("Hello World!")
Result: "HELLO WORLD!" |
| unique-id() | Generates and returns a unique, unquoted string, guaranteed to be unique during the current Sass session.
Example: unique-id()
Result: tyghefnsv |
| unquote(string) | Removes any quotes around string and returns the unquoted result.
Example: unquote("Hello world!")
Result: Hello world! |
