字符串
Sass 字符串函數(shù)
字符串函數(shù)用于操作和獲取有關(guān)字符串的信息。
Sass 字符串是從 1 開始的。字符串中的第一個(gè)字符位于索引 1,而不是 0。
下表列出了 Sass 中的所有字符串函數(shù):
函數(shù) | 描述 & 例子 |
---|---|
quote(string) |
將引號(hào)添加到字符串,并返回結(jié)果。 實(shí)例:quote(Hello world!) 結(jié)果:"Hello world!" |
str-index(string, substring) |
返回子字符串在字符串中第一次出現(xiàn)的索引。 實(shí)例:str-index("Hello world!", "H") 結(jié)果:1 |
str-insert(string, insert, index) |
返回在指定索引位置插入 insert 的字符串。 實(shí)例:str-insert("Hello world!", " wonderful", 6) 結(jié)果:"Hello wonderful world!" |
str-length(string) |
返回字符串的長(zhǎng)度(以字符計(jì))。 實(shí)例:str-length("Hello world!") 結(jié)果:12 |
str-slice(string, start, end) |
從字符串中提取字符;從 start 開始到 end 結(jié)束,并返回切片。 實(shí)例:str-slice("Hello world!", 2, 5) 結(jié)果:"ello" |
to-lower-case(string) |
返回轉(zhuǎn)換為小寫的字符串副本。 實(shí)例:to-lower-case("Hello World!") 結(jié)果:"hello world!" |
to-upper-case(string) |
返回轉(zhuǎn)換為大寫的字符串副本。 實(shí)例:to-upper-case("Hello World!") 結(jié)果:"HELLO WORLD!" |
unique-id() |
返回唯一的隨機(jī)生成的不帶引號(hào)的字符串(保證在當(dāng)前 sass 會(huì)話中是唯一的)。 實(shí)例:unique-id() 結(jié)果:tyghefnsv |
unquote(string) |
刪除字符串周圍的引號(hào)(如果有),并返回結(jié)果。 實(shí)例:unquote("Hello world!") 結(jié)果:Hello world! |