目录

Less - 字符串函数( String Functions)

描述 (Description)

Less支持下面列出的一些字符串函数 -

  • escape
  • e
  • %格式
  • replace

下表描述了上述字符串函数以及描述。

Sr.No. 类型和描述
1

Escape

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

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

它输出转义字符串为 -

Hello%21%21%20welcome%20to%20IoWiki%21
2

e

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

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

它输出转义字符串为 -

filter: Hello!! welcome to IoWiki!;
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 IoWiki!");

它将字符串替换为 -

"Welcome, to IoWiki!"
↑回到顶部↑
WIKI教程 @2018