String Builtins - HimxhMC/HimDSL GitHub Wiki
字符串函数速查 / String Built-ins Cheat Sheet
说明 / Note
本章是速查表。字符串的详细讲解(不可变性、转义、索引赋值等)在 [字符串与字符 / Strings-and-Chars]。
This is a cheat sheet. Full discussion (immutability, escapes, index assignment) is in [字符串与字符 / Strings-and-Chars].
字符串方法有两种调用形式:
String methods have two call forms:
-
方法形式:
s.length()——推荐。 -
函数形式:
length(s)——兼容早期脚本。 -
Method form:
s.length()— recommended. -
Function form:
length(s)— legacy.
两种完全等价,新代码统一用方法形式。
Both are equivalent; new code uses the method form.
速查 / Cheat Sheet
| 方法形式 | 函数形式 | 说明 |
|---|---|---|
s.length() |
length(s) |
长度 |
s.toUpperCase() |
toUpperCase(s) |
转大写 |
s.toLowerCase() |
toLowerCase(s) |
转小写 |
s.trim() |
trim(s) |
去首尾空白 |
s.contains(sub) |
contains(s, sub) |
包含子串 |
s.startsWith(prefix) |
startsWith(s, prefix) |
前缀 |
s.endsWith(suffix) |
endsWith(s, suffix) |
后缀 |
s.replace(old, new) |
replace(s, old, new) |
替换全部 |
s.split(sep) |
split(s, sep) |
分割为列表 |
| Method | Function | Meaning |
|---|---|---|
s.length() |
length(s) |
length |
s.toUpperCase() |
toUpperCase(s) |
uppercase |
s.toLowerCase() |
toLowerCase(s) |
lowercase |
s.trim() |
trim(s) |
strip edges |
s.contains(sub) |
contains(s, sub) |
substring test |
s.startsWith(prefix) |
startsWith(s, prefix) |
prefix |
s.endsWith(suffix) |
endsWith(s, suffix) |
suffix |
s.replace(old, new) |
replace(s, old, new) |
replace all |
s.split(sep) |
split(s, sep) |
split into list |
常用的两条 / Two Common Notes
拼接用 + / Concatenate with +
string msg = "玩家 " + name + " 上线";
split 参数是正则 / split Takes a Regex
"a.b.c".split("\\.") // ["a", "b", "c"]
"a,b,c".split(",") // ["a", "b", "c"]
普通分隔符(如逗号、空格)直接用。正则特殊字符(.、+、*、|)要加 \\。
Plain separators (comma, space) work directly. Regex metacharacters (., +, *, |) need \\.
小结 / Summary
-
用方法形式:
s.length(),不用length(s)。 -
上表是全部字符串内置。
-
详细讲解见《字符串与字符》。
-
Use the method form:
s.length(), notlength(s). -
The table above is the complete set.
-
Details in Strings & Chars.
下一步 / Next Steps
下一章 [集合函数速查 / Collection-Builtins] 类似——速查,详细内容见数据结构部分。
Next, [集合函数速查 / Collection-Builtins] is similar — lookup only; see the Data Structures section.