Repository navigation
String Builtins
本章是速查表。字符串的详细讲解(不可变性、转义、索引赋值等)在 [字符串与字符 / 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.
| 方法形式 | 函数形式 | 说明 |
|---|---|---|
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 |
string msg = "玩家 " + name + " 上线";
"a.b.c".split("\\.") // ["a", "b", "c"]
"a,b,c".split(",") // ["a", "b", "c"]
普通分隔符(如逗号、空格)直接用。正则特殊字符(.、+、*、|)要加 \\。
Plain separators (comma, space) work directly. Regex metacharacters (., +, *, |) need \\.
-
用方法形式:
s.length(),不用length(s)。 -
上表是全部字符串内置。
-
详细讲解见《字符串与字符》。
-
Use the method form:
s.length(), notlength(s). -
The table above is the complete set.
-
Details in Strings & Chars.
下一章 [集合函数速查 / Collection-Builtins] 类似——速查,详细内容见数据结构部分。
Next, [集合函数速查 / Collection-Builtins] is similar — lookup only; see the Data Structures section.
- 首页 / Home
- 安装与快速开始 / Installation & Quick Start
- 第一个脚本 / Your First Script
- 命令速查 / Command Reference
- 自动执行脚本 / Auto-run Scripts
- 定义函数 / Defining Functions
- 函数重载 / Function Overloading
- Lambda 表达式 / Lambda Expressions
- 函数式接口 / Functional Interfaces
- 选择器总览 / Selectors Overview
- 选择器过滤器 / Selector Filters
- EntityRef 引用 / EntityRef
- 占位符参考 / Placeholders Reference
- PlaceholderAPI 桥接 / PAPI Bridge
- 创建 GUI / Creating a GUI
- GUISlot 槽位 / GUISlot
- 点击回调 / Click Callbacks
- onClose 回调 / onClose Callback
- GUI 刷新 / GUI Refresh
- 数学函数 / Math Built-ins
- 高精度计算 / BigDecimal Built-ins
- 字符串函数 / String Built-ins
- 集合函数 / Collection Built-ins
- 文件 I/O / File I/O
- 命令与 sleep / Commands & sleep