-
Notifications
You must be signed in to change notification settings - Fork 0
API String
文本转换与处理
Text conversion and processing
Overview
AuroraScript 字符串是不可变值。所有实例方法都返回新文本或结果,不会修改原字符串。索引按 .NET UTF-16 code unit 计数。
AuroraScript strings are immutable values. Instance methods return new text or a result and never mutate the original string. Indexes count .NET UTF-16 code units.
Parameters:
-
value
可选待转换值。Optional value to convert.
Returns
字符串;缺失或不能转换时为空字符串。
A string; missing or non-convertible input becomes an empty string.
var left = String(42);
var right = String.valueOf(true);
return left + ":" + right; // 42:trueParameters:
-
charCode
字符编码。Character code.
Returns
单字符字符串。
One-character string.
return String.fromCharCode(65); // AParameters:
-
left、right
要比较的字符串。Strings to compare.
Returns
小于、等于或大于零的排序结果。
Ordering result below, equal to, or above zero.
return String.compare("a", "b") < 0; // trueReturns
字符串长度。
String length.
return "Aurora".length; // 6Parameters:
-
value
子串。Substring.
Returns
是否包含该子串。
Whether the substring occurs.
return "AuroraScript".contains("Script"); // trueParameters:
-
value
子串。Substring.
Returns
首次或最后一次匹配索引;未找到时为 -1。
First or last match index;
-1when missing.
var text = "a-b-a";
var first = text.indexOf("a");
return text.lastIndexOf("a") - first; // 4Parameters:
-
value
前缀或后缀。Prefix or suffix.
Returns
是否匹配。
Whether it matches.
var text = "AuroraScript";
return text.startsWith("Aurora") && text.endsWith("Script");Parameters:
-
start
起始索引。Starting index.
-
end
可选结束索引。Optional end index.
Returns
子字符串。
Substring.
边界行为
索引会被限制到有效范围;start > end 时运行时会交换它们。
Indexes are clamped to valid bounds; the runtime swaps
startandendwhenstart > end.
return "Aurora".substring(0, 3); // AurParameters:
-
start
起始索引。Starting index.
-
end
可选结束索引。Optional end index.
Returns
字符串切片。
String slice.
return "Aurora".slice(3); // oraParameters:
-
separator
可选分隔字符串。Optional separator string.
Returns
字符串数组;省略分隔符时返回只含原文本的数组。
Array of strings; omitting it returns an array containing the original text.
return "a,b,c".split(",").length; // 3Parameters:
-
pattern
Regex或模式字符串。Regexor pattern string.
Returns
匹配结果;没有匹配时为 null。
Match result, or
nullwhen there is no match.
return "v42".match(new Regex("[0-9]+"));Parameters:
-
pattern
带全局g标志的Regex或模式。Regexwith globalgflag or a pattern.
Returns
全部匹配构成的数组。
Array of all matches.
边界行为
全量匹配需要全局 Regex。
Full matching requires a global regex.
return "a1b2".matchAll(new Regex("[0-9]", "g")).length; // 2Parameters:
-
pattern
字符串或Regex。String or
Regex. -
replacement
替换字符串或回调。Replacement string or callback.
Returns
新字符串。
New string.
边界行为
全局 Regex 会替换所有匹配;普通字符串替换该文本的匹配。
A global regex replaces all matches; a string replacement uses the text match behavior.
return "a-b".replace("-", ":"); // a:bParameters:
-
width
目标长度。Target length.
-
padding
用作填充的字符串,其首字符用于填充。Padding string; its first character is used.
Returns
填充后的新字符串。
Padded new string.
var left = "7".padLeft(3, "0");
return left.padRight(4, "_"); // 007_Parameters:
- 无。
None.
Returns
去除两端、左端或右端空白后的新字符串。
New string with both, left, or right whitespace removed.
var text = " Aurora ";
return text.trimLeft().trimRight().trim(); // AuroraParameters:
-
index
字符索引。Character index.
Returns
UTF-16 code unit;越界时为 NaN。
UTF-16 code unit, or
NaNwhen out of range.
return "A".charCodeAt(0); // 65Parameters:
- 无。
None.
Returns
大小写转换后的新字符串。
New lower- or upper-case string.
var name = "Aurora";
return name.toLowerCase() + ":" + name.toUpperCase();Parameters:
- 无。
None.
Returns
原字符串。
The same string value.
return "Aurora".toString();AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License