template包 字符串函数

发布时间 2023-12-05 19:26:02作者: ExplorerMan
字符串函数
https://blog.gmem.cc/gotpl
函数 说明
abbrev 缩写参数,超出的字符以...代替。例如 abbrev "hello world"输出 he...
abbrevboth abbrevboth N STR:从双侧缩写
trunc trunc N STR:截断到指定长度
trim 去除空白
trimAll trimAll T STR:去除所有指定字符。例如 trimAll "$" "$5.00"输出 5.00
trimSuffix trimSuffix T STR:去除结尾的指定字符
trimPrefix trimPrefix T STR:去除前导的指定字符
upper 转换为大写
lower 转换为小写
nospace 移除所有空格
title string.Title
untitle 移除Title Case
repeat repeat N STR:重复指定次数
substr substr STR START LEN,截取子串:
initials 返回字符串中每个单词的首字母组成的缩写字符串
randAlphaNum randAlphaNum N:返回指定长度的随机字符串
randAlpha
randAscii
randNumeric
swapcase 切换大小写
shuffle 随机改变字符串中字符的顺序
snakecase 驼峰式大写转换为下划线
camelcase 下划线后的小写字符转换为大写,去除下划线
wrap wrap N STR:在指定长度处插入换行
wrapWith wrapWith N W STR:在指定长度处插入字符串W
contains contains SUB STR:是否包含子串
hasPrefix hasPrefix SUB STR:是否包含指定前缀
hasSuffix hasSuffix SUB STR:是否包含指定后缀
quote 以双引号包围,将"转义为\"
squote 以双引号包围,不进行转义
cat CAT S1 S2... 连接字符串,用空格
indent indent N STR:缩进字符串,例如 indent 4 "foo\nbar"输出     foo\n    bar 
nindent indent N STR:缩进字符串,并且为每行前添加一个换行符
replace 替换出现的子串,例如 $name | replace " " "-"
sha256sum 生成sha256哈希
toString 转换为字符串