Sass string functions

Sass string functions

Funkcje ciągów znaków są używane do operacji i uzyskiwania informacji o ciągu znaków.

Ciągi znaków w Sassie zaczynają się od 1. Pierwszy znak znajduje się na indeksie 1, a nie 0.

Poniższa tabela zawiera wszystkie funkcje ciągów znaków w Sassie:

Funkcja Opis i przykład
quote(string)

Dodaje znaki cudzysłów do ciągu znaków i zwraca wynik.

Example:

quote(Hello world!)

Wynik: "Hello world!"

str-index(string, substring)

Zwraca indeks pierwszego wystąpienia podciągu w ciągu znaków.

Example:

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

Wynik: 1

str-insert(string, insert, index)

Zwraca tekst włożony w określonym miejscu. insert ciągu znaków.

Example:

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

Wynik: "Hello wonderful world!"

str-length(string)

Zwraca długość ciągu znaków (licząc znaki).

Example:

str-length("Hello world!")

Result: 12

str-slice(string, start, end)

Extract characters from the string; from start To end End, and return the slice.

Example:

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

Result: "ello"

to-lower-case(string)

Returns a copy of the string converted to lowercase.

Example:

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

Result: "hello world!"

to-upper-case(string)

Returns a copy of the string converted to uppercase.

Example:

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

Result: "HELLO WORLD!"

unique-id()

Returns a unique randomly generated string without quotes (guaranteed to be unique in the current sass session).

Example:

unique-id()

Result: tyghefnsv

unquote(string)

Remove quotes around the string (if any) and return the result.

Example:

unquote("Hello world!")

Result: Hello world!