Sass String Functions
Sass string functions are used to process strings and obtain related information.
The starting index of a Sass string begins at 1, remember it is not 0.
The following table lists Sass's string functions:
| function | Description & Examples |
|---|---|
| quote(string) | Add quotes to a string. |
**实例:**
quote(runoob)
结果: "runoob" |
| str-index(string,* substring*) | Return the position where the substring first appears in string. If no substring is matched, return null.
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) | Inserts insert at the index position in the string string.
**实例:**
str-insert("Hello world!", " runoob", 6)
结果: "Hello runoob world!" |
| str-length(string) | Returns the length of a string.
**实例:**
str-length("runoob")
结果: 6 |
| str-slice(string, start, end) | Extracts a substring from string, setting the start and end positions via start-at and end-at. If no end index is specified, it defaults to extracting through 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) | Converts a string to lowercase
**实例:**
to-lower-case("RUNOOB")
结果: "runoob" |
| to-upper-case(string) | Converts a string to uppercase
**实例:**
to-upper-case("runoob")
结果: "RUNOOB" |
| unique-id() | Returns an unquoted random string to use as an id. However, it can only guarantee the uniqueness of this id within a single Sass compilation.
**实例:**
unique-id()
Result: uad053b1c |
| unquote(string) | Removes the quotes from a string
**实例:**
unquote("runoob")
结果: runoob |
Sass Functions