ucoreString
Text manipulation and regular expression support.
Functions
| Function | Returns | Description |
|---|---|---|
split(str, delimiter) |
Array | Split string into array |
join(array, delimiter) |
string | Join array into string |
replace(str, search, replace) |
string | Replace all occurrences |
trim(str) |
string | Remove whitespace |
toLower(str) |
string | Convert to lowercase |
toUpper(str) |
string | Convert to uppercase |
contains(str, substr) |
bool | Check if contains substring |
match(str, pattern) |
bool | Regex pattern match |
extract(str, pattern) |
Array | Extract all regex matches |
Basic Usage
split / join
var text = "apple,banana,cherry";
var parts = ucoreString.split(text, ",");
print(parts[0]); // "apple"
var joined = ucoreString.join(parts, " | ");
print(joined); // "apple | banana | cherry"
replace / trim
var dirty = " Hello World World ";
var trimmed = ucoreString.trim(dirty);
var clean = ucoreString.replace(trimmed, "World", "Unnarize");
print(clean); // "Hello Unnarize Unnarize"
Regular Expressions
Uses POSIX Extended Regular Expressions (ERE).
match(str, pattern)
Returns true if pattern matches anywhere in string.
if (ucoreString.match(text, "^Hello")) {
print("Starts with Hello");
}
extract(str, pattern)
Returns array of all non-overlapping matches.
var log = "Contact support@example.com or admin@site.org";
var emails = ucoreString.extract(log, "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}");
print(emails[0]); // "support@example.com"
print(emails[1]); // "admin@site.org"
Performance
Benchmarked on 14KB text (100 iterations):
| Operation | Ops/sec |
|---|---|
| contains | 24.5 Million |
| toLower | 42,500 |
| replace | 38,800 |
| split | 12,300 |
| regex extract | 2,600 |