思源笔记社区正在搭建中,现邀您共建
SiYuan Community is under construction. Join us to co-build.
trimtrim " hello "hellotrimAlltrimAll "$" "$5.00"5.00trimSuffixtrimSuffix "-" "hello-"hellotrimPrefixtrimPrefix "-" "-hello"helloupperupper "hello"HELLOlowerlower "HELLO"hellotitletitle "hello world"Hello Worlduntitleuntitle "Hello World"hello worldrepeatrepeat 3 "hello"hellohellohellosubstrsubstr 0 5 "hello world"hellonospacenospace "hello w o r l d"helloworldtrunctrunc 5 "hello world"hellotrunc -5 "hello world"worldabbrevabbrev 5 "hello world"he...,最大长度中包含三个英文句号组成的省略号abbrevbothabbrevboth 5 10 "1234 5678 9123"...5678...initialsinitials "First Try"FTrandAlphaNum,randAlpha,randNumeric,randAsciicrypto/rand 模块)randAlphaNum: 生成的随机字符串包含 0-9a-zA-ZrandAlpha: 生成的随机字符串包含 a-zA-ZrandNumeric: 生成的随机字符串包含 0-9randAscii: 生成的随机字符串包含所有可打印的 ASCII 字符randNumeric 33 个数字组成的随机字符串wrap\n 换行wrap 80 $someText$someText 中81 个字符为空格,则将第 81 个字符替换为 \n81 个字符不为空格,则将 80 个字符中最后的一个空格替换为换行符 \n80 个字符中不存在空格,则在第 80 个字符后插入一个换行符 \nwrapWithwrap 相似,在指定列处使用使用指定的字符串作为换行符号进行换行wrapWith 5 "\t" "Hello World"Hello World (空白字符为制表符 \t)containscontains "cat" "catch"true,因为字符串 catch 包含字符串 cathasPrefix,hasSuffixhasPrefix)或后缀(hasSuffix)hasPrefix "cat" "catch"true,因为字符串 catch 包含前缀 catquote,squotequote) 或单引号 (squote) 包括一个字符串quote "abc""abc"squote "def"'def'catcat 函数可将多个字符串拼接为一个字符串 (拼接后的字符串使用空格分隔)cat "hello" "beautiful" "world"hello beautiful worldindentindent 函数可将给定的字符串中每一行都缩进到指定的宽度 (用于对齐多行字符串)indent 4 $lots_of_textnindentnindent 函数的功能与 indent 函数相同,但是会在字符串开头插入一个新行 (空行)nindent 4 $lots_of_textreplace"I Am Henry VIII" | replace " " "-"
replace " " "-" "I Am Henry VIII"I-Am-Henry-VIIIplurallen $fish | plural "one anchovy" "many anchovies"
plural "one anchovy" "many anchovies" (len $fish)len $fish 为 1,那么第一个参数 one anchovy 将会被返回,否则第二个参数 many anchovies 将会被返回0 被认为是复数形式,因为英语将其视为复数形式(zero anchovies)。snakecasesnakecase "FirstName"first_namecamelcasecamelcase "http_server"HttpServerkebabcasekebabcase "FirstName"first-nameswapcaseunicode.IsSpace(char) 判断swapcase "This Is A.Test"tHIS iS a.tESTshuffleshuffle "hello"hello 中的字母,可能返回 oelhlregexMatch,mustRegexMatchtrueregexMatch "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$" "test@acme.com"trueregexMatch 出现异常时会抛出 panic,mustRegexMathc 出现异常时会向模板引擎返回一个 errorregexFindAll,mustRegexFindAlln 确定要返回的子字符串数,其中 -1 表示返回所有匹配项。regexFindAll "[2,4,6,8]" "123456789" -1[2 4 6 8]regexFindAll 出现异常时会抛出 panic,mustRegexFindAll 出现异常时会向模板引擎返回一个 errorregexFind,mustRegexFindregexFind "[a-zA-Z][1-9]" "abcd1234"d1regexFind 出现异常时会抛出 panic,mustRegexFind 出现异常时会向模板引擎返回一个 errorregexReplaceAll,mustRegexReplaceAll$具有特殊含义,例如 ${1} 表示第一个分组匹配的文本。regexReplaceAll "a(x*)b" "-ab-axxb-" "${1}W"-W-xxW-regexReplaceAll 出现异常时会抛出 panic,mustRegexReplaceAll 出现异常时会向模板引擎返回一个 errorregexReplaceAllLiteral,mustRegexReplaceAllLiteralregexReplaceAllLiteral "a(x*)b" "-ab-axxb-" "${1}"-{1}-regexReplaceAllLiteral 出现异常时会抛出 panic,mustRegexReplaceAllLiteral 出现异常时会向模板引擎返回一个 errorregexSplit,mustRegexSplitn 确定要返回的子字符串数,其中 -1 表示返回所有匹配项。regexSplit "z+" "pizza" -1[pi a]regexSplit 出现异常时会抛出 panic,mustRegexSplit 出现异常时会向模板引擎返回一个 errorregexQuoteMetaregexQuoteMeta "1.2.3"1\.2\.3