LESS - 字符串函数

说明

Less 支持下面列出的部分字符串函数 −

  • escape
  • e
  • % format
  • replace

下表介绍了上述字符串函数及其说明。

Sr.No. 类型 &描述 示例
1

转义

使用 URL 编码对特殊字符进行编码,对字符串或信息进行编码。您无法对某些字符进行编码,例如 ,/?@&+~!$' 以及您可以编码的某些字符,例如 \#^(){>:><][=

escape("Hello!! welcome to Tutorialspoint!")

它将转义字符串输出为 −

Hello%21%21%20welcome%20to%20Tutorialspoint%21
2

e

这是一个字符串函数,使用字符串作为参数并返回不带引号的信息。这是一个 CSS 转义,使用 ~"some content" 转义值和数字作为参数。

filter: e("Hello!! welcome to Tutorialspoint!");

它将转义字符串输出为 −

filter: Hello!! welcome to Tutorialspoint!;
3

% format

此函数格式化字符串。可以采用以下格式编写 −

%(string, arguments ...)
format-a-d: %("myvalues: %a myfile: %d", 2 + 3, 
"mydir/less_demo.less");

它将格式化的字符串输出为 −

format-a-d: "myvalues: 5 myfile: 
"mydir/less_demo.less"";
4

replace

它用于替换字符串中的文本。它使用一些参数 −

  • string − 它搜索字符串并替换。

  • pattern − 它搜索正则表达式模式。

  • replacement − 它替换与模式匹配的字符串。

  • flags − 这些是可选的正则表达式标志。

replace("Welcome, val?", "val\?", 
"to Tutorialspoint!");

它将字符串替换为 −

"Welcome, to Tutorialspoint!"