CoreModules.String) provides comprehensive string manipulation capabilities, including pattern matching, formatting, and text processing.
Important: UTF-16 Encoding
String Metatable
SolarSharp automatically sets the string metatable with__index pointing to the string module, enabling object-oriented style calls:
Basic Functions
string.len(s)
Returns the length of a string in UTF-16 code units.string.upper(s) / string.lower(s)
Converts string to uppercase or lowercase.string.reverse(s)
Reverses a string.Character Operations
string.byte(s [, i [, j]])
Returns the UTF-16 code units of characters in the string.s- Input stringi- Start position (default: 1)j- End position (default: i)
string.char(…)
Converts UTF-16 code units to a string.Substring Operations
string.sub(s, i [, j])
Extracts a substring.string.rep(s, n [, sep])
Repeats a string n times with optional separator.Pattern Matching
string.find(s, pattern [, init [, plain]])
Finds the first occurrence of a pattern.nil if not found.
string.match(s, pattern [, init])
Extracts the first match of a pattern.string.gmatch(s, pattern)
Returns an iterator function for all matches.string.gsub(s, pattern, repl [, n])
Replaces occurrences of a pattern.String Formatting
string.format(formatstring, …)
Formats a string using printf-style formatting.| Specifier | Description | Example |
|---|---|---|
%s | String | string.format("%s", "text") |
%d, %i | Integer | string.format("%d", 42) |
%f | Float | string.format("%.2f", 3.14) |
%e | Scientific notation | string.format("%e", 1000) |
%x, %X | Hexadecimal | string.format("%x", 255) |
%c | Character | string.format("%c", 65) |
%q | Quoted string | string.format("%q", "test") |
%% | Literal % | string.format("100%%") |
-: Left justify+: Show sign for numbers0: Zero padding#: Alternate form (e.g.,0xprefix): Space for positive numbers
SolarSharp Extensions
These functions are SolarSharp-specific extensions:string.startsWith(s1, s2)
Checks if a string starts with another string.string.endsWith(s1, s2)
Checks if a string ends with another string.string.contains(s1, s2)
Checks if a string contains another string.string.dump(function)
Serializes a function to a base64-encoded string.Pattern Syntax
SolarSharp supports Lua pattern matching: Character Classes:.: Any character%a: Letters%d: Digits%s: Space characters%w: Alphanumeric characters%x: Hexadecimal digits%c,%l,%p,%u: Control, lowercase, punctuation, uppercase
*: 0 or more repetitions+: 1 or more repetitions-: 0 or more (non-greedy)?: 0 or 1 occurrence
[set]: Character set[^set]: Complement of set^: Beginning of string$: End of string(): Capture group