Sass 字串函式
Sass 字串函式
字串函式用於操作和獲取關於字串的資訊。
Sass 字串是從 1 開始索引的。字串中的第一個字元的索引是 1,而不是 0。
下表列出了 Sass 中的所有字串函式
函式 | 描述 & 示例 |
---|---|
quote(string) | 為 string 新增引號,並返回結果。 示例 quote(Hello world!) 結果: "Hello world!" |
str-index(string, substring) | 返回 substring 在 string 中第一次出現的位置索引。 示例 str-index("Hello world!", "H") 結果: 1 |
str-insert(string, insert, index) | 返回 string,並在指定的 index 位置插入 insert。 示例 str-insert("Hello world!", " wonderful", 6) 結果: "Hello wonderful world!" |
str-length(string) | 返回 string 的長度(以字元為單位)。 示例 str-length("Hello world!") 結果: 12 |
str-slice(string, start, end) | 從 string 中提取字元;從 start 開始,到 end 結束,並返回切片。 示例 str-slice("Hello world!", 2, 5) 結果: "ello" |
to-lower-case(string) | 返回一個轉換為小寫的 string 的副本。 示例 to-lower-case("Hello World!") 結果: "hello world!" |
to-upper-case(string) | 返回一個轉換為大寫的 string 的副本。 示例 to-upper-case("Hello World!") 結果: "HELLO WORLD!" |
unique-id() | 返回一個唯一生成的隨機無引號字串(保證在當前 Sass 會話中是唯一的)。 示例 unique-id() 結果: tyghefnsv |
unquote(string) | 移除 string 周圍的引號(如果有),並返回結果。 示例 unquote("Hello world!") 結果: Hello world! |