字符串
文章目录
字符串函数
常用于操作和获取有关字符串的信息,字符串是基于1的,字符串中的第一个字符是位于索引1而不是0。
下面是关于所有字符串函数的一个相关整理:
-
quote(string),向字符串添加引号,并返回结果
quote(Welcome to xkd!) Result: "Welcome to xkd!" -
str-index(string , substring),返回字符串中第一个出现的子字符串的索引
str-index("Welcome to xkd!", "W") Result: 1 -
str-insert(string , insert , index),返回指定索引位置插入insert的字符串
str-insert("Welcome to xkd!", " our", 8) Result: "Welcome to our xkd!" -
str-length(string),返回字符串的长度(以字符为单位)
str-length("Hello world!") Result: 12 -
str-slice(string , strat , end),从字符串中提取字符,从开始处开始到结束处结束,并返回切片
str-slice("Hello world!", 2, 5) Result: "ello" -
to-lower-case(string),返回转换为小写的字符串副本
to-lower-case("Welcome to xkd!") Result: "welcome to xkd!" -
to-upper-case(string),返回转换为大写的字符串副本
to-upper-case("Welcome to xkd!") Result: "WELCOME TO XKD!" -
unique-id(),返回一个随机生成的不带引号的唯一的字符串(保证当前sass会话中是唯一的)
unique-id() Result: afvagfvakj -
unquote(string),如果字符周围有引号将移除,并返回结果
unquote("Welcome to xkd!") Result: Welcome to xkd!
字符串类型
- 有引号字符串(quoted strings)
- 无引号字符串(unquoted strings)
注意:在使用 #{}(interpolation)时,有引号字符串将会被编译为无引号字符串,这样便于在 mixin 中引用选择器名。
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论