LESS - 字串函式



描述

Less 支援以下列出的某些字串函式:

  • 轉義
  • e
  • % 格式化
  • 替換

下表描述了上述字串函式及其描述。

序號 型別和描述 示例
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

% 格式化

此函式格式化字串。它可以用以下格式編寫:

%(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("Welcome, val?", "val\?", 
"to Tutorialspoint!");

它替換字串為:

"Welcome, to Tutorialspoint!"
廣告

© . All rights reserved.