Sass String Functies

Sass String Functies

字符串函数用于操作和获取有关字符串的信息。

Sass 字符串是从 1 开始的。字符串中的第一个字符位于索引 1,而不是 0。

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

函数 描述 & 示例
quote(string)

将引号添加到字符串,并返回结果。

Voorbeeld:

quote(Hello world!)

结果:"Hello world!"

str-index(string, substring)

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

Voorbeeld:

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

结果:1

str-insert(string, insert, index)

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

Voorbeeld:

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

结果:"Hello wonderfull world!"

str-length(string)

返回性字符串的长度(以字符计)。

Voorbeeld:

str-length("Hello world!")

Resultaat: 12

str-slice(string, start, end)

Tekens ophalen uit een string; van start Vanaf end Einde, en retourneer het snede.

Voorbeeld:

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

Resultaat: "ello"

to-lower-case(string)

Retourneert een kopie van de string in kleine letters.

Voorbeeld:

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

Resultaat: "hello world!"

to-upper-case(string)

Retourneert een kopie van de string in hoofdletters.

Voorbeeld:

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

Resultaat: "HELLO WORLD!"

unique-id()

Retourneert een unieke willekeurig gegenereerde string zonder aanhalingstekens (wordt in de huidige sass-sessie als uniek beschouwd).

Voorbeeld:

unique-id()

Resultaat: tyghefnsv

unquote(string)

Verwijder de aanhalingstekens rond de string (indien aanwezig) en retourneer het resultaat.

Voorbeeld:

unquote("Hello world!")

Resultaat: Hello world!