String Methods
DOCUMENTATION
XCX 4.4.1 String Methods
String objects in XCX are immutable. Methods return a new string and do not modify the original.
Properties
.length: Returns the number of Unicode code points in the string (e.g.,"zażółć".lengthis 6). Used without parentheses.
Escape Sequences
String literals support standard escape sequences:
| Sequence | Effect |
|---|---|
\n | Newline |
\t | Horizontal Tab |
\r | Carriage Return |
\" | Double Quote |
\\ | Backslash |
\xNN | Hexadecimal character (e.g., \x1b) |
\NNN | Octal character (e.g., \033) |
Methods
| Method | Signature | Description |
|---|---|---|
.upper() | () → s | Converts all characters to uppercase. |
.lower() | () → s | Converts all characters to lowercase. |
.trim() | () → s | Removes leading/trailing whitespace. |
.replace(f, t) | (s, s) → s | Replaces all occurrences of f with t. |
.slice(s, e) | (i, i) → s | Returns substring from index s up to e. |
.indexOf(s) | (s) → i | Returns index of first occurrence, or -1. |
.lastIndexOf(s) | (s) → i | Returns index of last occurrence, or -1. |
.startsWith(s) | (s) → b | Returns true if string starts with s. |
.endsWith(s) | (s) → b | Returns true if string ends with s. |
.toInt() | () → i | Parses string to Integer; halt.error if fail. |
.toFloat() | () → f | Parses string to Float; halt.error if fail. |
.split(s) | (s) → array:s | Splits by separator s; returns array of strings. |
Examples
xcx
_
⛶
×
1s: raw = " XCX-Language ";
2s: clean = raw.trim().lower().replace("-", "_"); --- "xcx_language"
3
4i: start = "Programming".indexOf("gram"); --- 3
5s: part = "Programming".slice(0, 4); --- "Prog"
6
7i: age = "25".toInt();
8array:s: parts = "a,b,c".split(","); --- {"a", "b", "c"}