sass:string
- Dart Sass
- since 1.23.0
- LibSass
- ✗
- Ruby Sass
- ✗
Only Dart Sass currently supports loading built-in modules with @use
. Users
of other implementations must call functions using their global names instead.
string.quote($string)
quote($string) //=> string
返回 $string
作为带引号的字符串。
¥Returns $string
as a quoted string.
SCSS Syntax
@use "sass:string";
@debug string.quote(Helvetica); // "Helvetica"
@debug string.quote("Helvetica"); // "Helvetica"
Sass Syntax
@use "sass:string"
@debug string.quote(Helvetica) // "Helvetica"
@debug string.quote("Helvetica") // "Helvetica"
string.index($string, $substring)
str-index($string, $substring) //=> number
返回 $string
中 $substring
的第一个 索引,如果 $string
不包含 $substring
,则返回 null
。
¥Returns the first index of $substring
in $string
, or null
if
$string
doesn’t contain $substring
.
SCSS Syntax
@use "sass:string";
@debug string.index("Helvetica Neue", "Helvetica"); // 1
@debug string.index("Helvetica Neue", "Neue"); // 11
Sass Syntax
@use "sass:string"
@debug string.index("Helvetica Neue", "Helvetica") // 1
@debug string.index("Helvetica Neue", "Neue") // 11
string.insert($string, $insert, $index)
str-insert($string, $insert, $index) //=> string
返回 $string
的副本,其中 $insert
插入到 $index
处。
¥Returns a copy of $string
with $insert
inserted at $index
.
SCSS Syntax
@use "sass:string";
@debug string.insert("Roboto Bold", " Mono", 7); // "Roboto Mono Bold"
@debug string.insert("Roboto Bold", " Mono", -6); // "Roboto Mono Bold"
Sass Syntax
@use "sass:string"
@debug string.insert("Roboto Bold", " Mono", 7) // "Roboto Mono Bold"
@debug string.insert("Roboto Bold", " Mono", -6) // "Roboto Mono Bold"
如果 $index
大于 $string
的长度,则将 $insert
添加到末尾。如果 $index
小于字符串的负长度,则将 $insert
添加到开头。
¥If $index
is higher than the length of $string
, $insert
is added to the
end. If $index
is smaller than the negative length of the string, $insert
is added to the beginning.
SCSS Syntax
@use "sass:string";
@debug string.insert("Roboto", " Bold", 100); // "Roboto Bold"
@debug string.insert("Bold", "Roboto ", -100); // "Roboto Bold"
Sass Syntax
@use "sass:string"
@debug string.insert("Roboto", " Bold", 100) // "Roboto Bold"
@debug string.insert("Bold", "Roboto ", -100) // "Roboto Bold"
string.length($string)
str-length($string) //=> number
返回 $string
中的字符数。
¥Returns the number of characters in $string
.
SCSS Syntax
@use "sass:string";
@debug string.length("Helvetica Neue"); // 14
@debug string.length(bold); // 4
@debug string.length(""); // 0
Sass Syntax
@use "sass:string"
@debug string.length("Helvetica Neue") // 14
@debug string.length(bold) // 4
@debug string.length("") // 0
string.slice($string, $start-at, $end-at: -1)
str-slice($string, $start-at, $end-at: -1) //=> string
返回 $string
的切片,从 索引 $start-at
开始,到索引 $end-at
结束(包括两者)。
¥Returns the slice of $string
starting at index $start-at
and ending at
index $end-at
(both inclusive).
SCSS Syntax
@use "sass:string";
@debug string.slice("Helvetica Neue", 11); // "Neue"
@debug string.slice("Helvetica Neue", 1, 3); // "Hel"
@debug string.slice("Helvetica Neue", 1, -6); // "Helvetica"
Sass Syntax
@use "sass:string"
@debug string.slice("Helvetica Neue", 11) // "Neue"
@debug string.slice("Helvetica Neue", 1, 3) // "Hel"
@debug string.slice("Helvetica Neue", 1, -6) // "Helvetica"
string.split($string, $separator, $limit: null) //=> list
- Dart Sass
- since 1.57.0
- LibSass
- ✗
- Ruby Sass
- ✗
返回 $string
中以逗号分隔的括号内的子字符串列表,这些子字符串由 $separator
分隔。$separator
不包含在这些子字符串中。
¥Returns a bracketed, comma-separated list of substrings of $string
that are
separated by $separator
. The $separator
s aren’t included in these substrings.
如果 $limit
是数字 1
或更高,则最多会分割 $separator
个数字(因此最多返回 $limit + 1
个字符串)。最后一个子字符串包含字符串的其余部分,包括任何剩余的 $separator
。
¥If $limit
is a number 1
or higher, this splits on at most that many
$separator
s (and so returns at most $limit + 1
strings). The last
substring contains the rest of the string, including any remaining
$separator
s.
SCSS Syntax
@use "sass:string";
@debug string.split("Segoe UI Emoji", " "); // ["Segoe", "UI", "Emoji"]
@debug string.split("Segoe UI Emoji", " ", $limit: 1); // ["Segoe", "UI Emoji"]
Sass Syntax
@use "sass:string"
@debug string.split("Segoe UI Emoji", " ") // ["Segoe", "UI", "Emoji"]
@debug string.split("Segoe UI Emoji", " ", $limit: 1) // ["Segoe", "UI Emoji"]
string.to-upper-case($string)
to-upper-case($string) //=> string
返回 $string
的副本,其中 ASCII 字母转换为大写。
¥Returns a copy of $string
with the ASCII letters converted to upper case.
SCSS Syntax
@use "sass:string";
@debug string.to-upper-case("Bold"); // "BOLD"
@debug string.to-upper-case(sans-serif); // SANS-SERIF
Sass Syntax
@use "sass:string"
@debug string.to-upper-case("Bold") // "BOLD"
@debug string.to-upper-case(sans-serif) // SANS-SERIF
string.to-lower-case($string)
to-lower-case($string) //=> string
返回 $string
的副本,其中 ASCII 字母转换为小写。
¥Returns a copy of $string
with the ASCII letters converted to lower case.
SCSS Syntax
@use "sass:string";
@debug string.to-lower-case("Bold"); // "bold"
@debug string.to-lower-case(SANS-SERIF); // sans-serif
Sass Syntax
@use "sass:string"
@debug string.to-lower-case("Bold") // "bold"
@debug string.to-lower-case(SANS-SERIF) // sans-serif
string.unique-id()
unique-id() //=> string
返回一个随机生成的不带引号的字符串,该字符串保证是有效的 CSS 标识符,并且在当前 Sass 编译中是唯一的。
¥Returns a randomly-generated unquoted string that’s guaranteed to be a valid CSS identifier and to be unique within the current Sass compilation.
SCSS Syntax
@use "sass:string";
@debug string.unique-id(); // uabtrnzug
@debug string.unique-id(); // u6w1b1def
Sass Syntax
@use "sass:string"
@debug string.unique-id(); // uabtrnzug
@debug string.unique-id(); // u6w1b1def
string.unquote($string)
unquote($string) //=> string
返回 $string
作为不带引号的字符串。这可能会生成无效 CSS 的字符串,因此请谨慎使用。
¥Returns $string
as an unquoted string. This can produce strings that aren’t
valid CSS, so use with caution.
SCSS Syntax
@use "sass:string";
@debug string.unquote("Helvetica"); // Helvetica
@debug string.unquote(".widget:hover"); // .widget:hover
Sass Syntax
@use "sass:string"
@debug string.unquote("Helvetica") // Helvetica
@debug string.unquote(".widget:hover") // .widget:hover