-
Notifications
You must be signed in to change notification settings - Fork 0
API String
Text conversion helpers and the immutable string instance API.
AuroraScript strings are immutable values. Every instance method returns new text or a computed result and never mutates the original string. Indexes count .NET UTF-16 code units.
String is callable, so String(value) converts a value directly and always produces a primitive string rather than a wrapper object.
| Member | Returns | Summary |
|---|---|---|
String([value]) |
string |
Converts a value to a string. |
String.valueOf(value) |
string |
Converts a value to a string. |
String.fromCharCode(charCode) |
string |
Creates a one-character string from a character code. |
String.compare(left, right) |
number |
Compares two strings and returns their ordering. |
text.length |
number |
Number of UTF-16 code units. |
text.contains(value) |
boolean |
Reports whether a substring occurs. |
text.indexOf(value) |
number |
First index of a substring. |
text.lastIndexOf(value) |
number |
Last index of a substring. |
text.startsWith(value) |
boolean |
Reports whether the string starts with a prefix. |
text.endsWith(value) |
boolean |
Reports whether the string ends with a suffix. |
text.substring(start, [end]) |
string |
Extracts a substring. |
text.slice(start, [end]) |
string |
Extracts a slice. |
text.split([separator]) |
array |
Splits the string into an array. |
text.match(pattern) |
any |
Matches against a regex or pattern. |
text.matchAll(pattern) |
array |
Returns all matches. |
text.replace(pattern, replacement) |
string |
Replaces matched text. |
text.padLeft(width, padding) |
string |
Pads the string on the left. |
text.padRight(width, padding) |
string |
Pads the string on the right. |
text.trim() |
string |
Trims both ends. |
text.trimLeft() |
string |
Trims the left end. |
text.trimRight() |
string |
Trims the right end. |
text.charCodeAt(index) |
number |
Character code at an index. |
text.toLowerCase() |
string |
Lowercase copy. |
text.toUpperCase() |
string |
Uppercase copy. |
text.toString() |
string |
Returns the same string value. |
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value |
any |
No | Value to convert. |
Returns
string — the converted text.
Behavior
Missing or non-string-convertible input produces an empty string.
Example
return String(42); // "42"Returns
number — the string length in UTF-16 code units.
Example
return "Aurora".length; // 6Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value |
any |
Yes | Value to convert. |
Returns
string — the converted text.
Example
return String.valueOf(true); // "true"Parameters
| Name | Type | Required | Description |
|---|---|---|---|
charCode |
number |
Yes | UTF-16 character code. |
Returns
string — a one-character string.
Example
return String.fromCharCode(65); // "A"Parameters
| Name | Type | Required | Description |
|---|---|---|---|
left |
string |
Yes | First string in the comparison. |
right |
string |
Yes | Second string in the comparison. |
Returns
number — negative when left sorts first, zero when the strings are equal, positive when right sorts first.
Example
return String.compare("a", "b") < 0; // trueParameters
| Name | Type | Required | Description |
|---|---|---|---|
value |
string |
Yes | Substring to search for. |
Returns
boolean — whether the substring occurs.
Example
return "AuroraScript".contains("Script"); // trueParameters
| Name | Type | Required | Description |
|---|---|---|---|
value |
string |
Yes | Substring to search for. |
Returns
number — the first match index, or -1 when the substring is missing.
Example
return "a-b-a".indexOf("a"); // 0Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value |
string |
Yes | Substring to search for. |
Returns
number — the last match index, or -1 when the substring is missing.
Example
return "a-b-a".lastIndexOf("a"); // 4Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value |
string |
Yes | Prefix to test. |
Returns
boolean — whether the string starts with the prefix.
Example
return "AuroraScript".startsWith("Aurora"); // trueParameters
| Name | Type | Required | Description |
|---|---|---|---|
value |
string |
Yes | Suffix to test. |
Returns
boolean — whether the string ends with the suffix.
Example
return "AuroraScript".endsWith("Script"); // trueParameters
| Name | Type | Required | Description |
|---|---|---|---|
start |
number |
Yes | Index of the first code unit to copy. |
end |
number |
No | Index after the last code unit to copy. |
Returns
string — the extracted substring.
Behavior
Indexes are clamped to the valid bounds of the string, and the runtime swaps start and end when start > end.
Example
return "Aurora".substring(0, 3); // "Aur"Parameters
| Name | Type | Required | Description |
|---|---|---|---|
start |
number |
Yes | Index of the first code unit to copy. |
end |
number |
No | Index after the last code unit to copy. |
Returns
string — the extracted slice.
Example
return "Aurora".slice(3); // "ora"Parameters
| Name | Type | Required | Description |
|---|---|---|---|
separator |
string |
No | Delimiter that separates the segments. |
Returns
array — the resulting segments.
Behavior
Omitting the separator returns an array containing the original text as its only element.
Example
return "a,b,c".split(",").length; // 3Parameters
| Name | Type | Required | Description |
|---|---|---|---|
pattern |
regex or string
|
Yes | A Regex instance or a pattern string. |
Returns
any — the match result, or null when there is no match.
Example
return "v42".match(new Regex("[0-9]+"));Parameters
| Name | Type | Required | Description |
|---|---|---|---|
pattern |
regex or string
|
Yes | A Regex instance or a pattern string. |
Returns
array — every match found in the string.
Important
Collecting all matches requires a global regex. Pass the g flag, as in new Regex("[0-9]", "g").
Example
return "a1b2".matchAll(new Regex("[0-9]", "g")).length; // 2Parameters
| Name | Type | Required | Description |
|---|---|---|---|
pattern |
string or regex
|
Yes | Literal text or a Regex instance to match. |
replacement |
string or function
|
Yes | Replacement text, or a callback that produces the replacement for each match. |
Returns
string — new text with the matches replaced.
Behavior
A global regex replaces every match. A string pattern uses literal text-match replacement semantics.
Example
return "a-b".replace("-", ":"); // "a:b"Parameters
| Name | Type | Required | Description |
|---|---|---|---|
width |
number |
Yes | Target total length. |
padding |
string |
Yes | Padding text; its first character is used. |
Returns
string — the padded text.
Example
return "7".padLeft(3, "0"); // "007"Parameters
| Name | Type | Required | Description |
|---|---|---|---|
width |
number |
Yes | Target total length. |
padding |
string |
Yes | Padding text; its first character is used. |
Returns
string — the padded text.
Example
return "7".padRight(3, "_"); // "7__"Parameters
None.
Returns
string — new text with leading and trailing whitespace removed.
Example
return " Aurora ".trim(); // "Aurora"Parameters
None.
Returns
string — new text with leading whitespace removed.
Example
return " Aurora".trimLeft(); // "Aurora"Parameters
None.
Returns
string — new text with trailing whitespace removed.
Example
return "Aurora ".trimRight(); // "Aurora"Parameters
| Name | Type | Required | Description |
|---|---|---|---|
index |
number |
Yes | Zero-based code-unit index. |
Returns
number — the UTF-16 code unit at the index.
Behavior
An index outside the string returns NaN rather than raising an error.
Example
return "A".charCodeAt(0); // 65Parameters
None.
Returns
string — a lowercase copy.
Example
return "Aurora".toLowerCase(); // "aurora"Parameters
None.
Returns
string — an uppercase copy.
Example
return "Aurora".toUpperCase(); // "AURORA"Parameters
None.
Returns
string — the same string value.
Example
return "Aurora".toString(); // "Aurora"AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License