讲师中心 微信公众号

工具推荐

视频效率加速
AniShort
AniShort

AI短剧协同制作平台

SoundView
SoundView

字幕擦除翻译、配音口型同步

Seko
Seko

AI短剧一键生成成片

立刻MV
立刻MV

低成本歌曲 MV、视频生成

Sass 教程

浏览9027
更新时间2025-08-14

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!

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn