Sass 字符串函數

Sass 字符串函數

字符串函數用于操作和獲取有關字符串的信息。

Sass 字符串是從 1 開始的。字符串中的第一個字符位于索引 1,而不是 0。

下表列出了 Sass 中的所有字符串函數:

函數 描述 & 例子
quote(string)

將引號添加到字符串,并返回結果。

實例:

quote(Hello world!)

結果:"Hello world!"

str-index(string, substring)

返回子字符串在字符串中第一次出現的索引。

實例:

str-index("Hello world!", "H")

結果:1

str-insert(string, insert, index)

返回在指定索引位置插入 insert 的字符串。

實例:

str-insert("Hello world!", " wonderful", 6)

結果:"Hello wonderful world!"

str-length(string)

返回字符串的長度(以字符計)。

實例:

str-length("Hello world!")

結果:12

str-slice(string, start, end)

從字符串中提取字符;從 start 開始到 end 結束,并返回切片。

實例:

str-slice("Hello world!", 2, 5)

結果:"ello"

to-lower-case(string)

返回轉換為小寫的字符串副本。

實例:

to-lower-case("Hello World!")

結果:"hello world!"

to-upper-case(string)

返回轉換為大寫的字符串副本。

實例:

to-upper-case("Hello World!")

結果:"HELLO WORLD!"

unique-id()

返回唯一的隨機生成的不帶引號的字符串(保證在當前 sass 會話中是唯一的)。

實例:

unique-id()

結果:tyghefnsv

unquote(string)

刪除字符串周圍的引號(如果有),并返回結果。

實例:

unquote("Hello world!")

結果:Hello world!