Skip to content

String Builtins

Himxh edited this page Oct 4, 2026 · 1 revision

字符串函数速查 / 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(), not length(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.


HimDSL 文档 / Documentation

入门 / Getting Started

语言基础 / Language Basics

控制流 / Control Flow

函数 / Functions

数据结构 / Data Structures

自定义类型 / Custom Types

Minecraft 集成 / Minecraft Integration

事件与调度 / Events & Scheduling

GUI 系统 / GUI System

内置函数参考 / Built-ins Reference

进阶 / Advanced

扩展 API / Extension API

你真的需要 API 吗?/ Do you really need the API?

Clone this wiki locally