The string
module
The string
module provides functions for manipulating strings. It also serves to be the string metatable. Strings have collection
as their metatable.
Free functions
builder(start: number | string | null): native
Create a new string builder. If start
is a string, the builder will start with that string. If start
is a number, the builder will start with the specified capacity. If start
is null
, the builder will start with a capacity that is implementation-defined.
Member functions
charCode(self): number
Get the character code of the first character in the string.
encode(self, encoding: string = “UTF−8”): bytes
Encode the string using the specified encoding. The default encoding is UTF−8.
equalIgnoreCase(self, other: string): boolean
Compare two strings for equality, ignoring case.
isBlank(self): boolean
Check if the string is blank. A string is blank if it is empty or if it only contains whitespace.
isDigit(self): boolean
Check if the string is solely made up of digits.
isLetter(self): boolean
Check if the string is solely made up of letters.
isLetterOrDigit(self): boolean
Check if the string is solely made up of letters or digits.
isLowercase(self): boolean
Check if the string is solely made up of lowercase letters.
isUppercase(self): boolean
Check if the string is solely made up of uppercase letters.
isWhitespace(self): boolean
Check if the string is solely made up of whitespace.
lowercase(self): string
Convert the string to lowercase.
remove(self, start: number, end: number | null): string
Remove a range of characters from the string from start
to end
(exclusive). If end
is null
, the substring will end at the end of the string.
repeat(self, count: number): string
Repeat the string count
times.
replace(self, pattern: string, replacement: string): string
Replace all occurrences of pattern
with replacement
.
reversed(self): string
Return a reversed copy of the string.
size(self): number
Get the number of characters in the string.
split(self, separator: string): list[string]
Split the string into an array of strings, using separator
as the delimiter.
strip(self): string
Strip whitespace from the beginning and end of the string.
stripLeft(self): string
Strip whitespace from the beginning of the string.
stripRight(self): string
Strip whitespace from the end of the string.
sub(self, start: number, end: number | null): string
Get a substring of the string. If end
is null
, the substring will end at the end of the string.
uppercase(self): string
Convert the string to uppercase.
Metamethods
__cmp__(self, other: string): number
Compare two strings.
__contains__(self, other: string): boolean
Check if the string contains another string.
__eq__(self, other: string): boolean
Check if two strings are equal.
__index__(self, index: number): string
Get the character at the specified index.
__iter__(self): table
Get an iterator for the string.
__plus__(self, other: string): string
Concatenate two strings.
String builders
String builders are the Metis analog of Java’s StringBuilder
class. They are used to efficiently build strings, as opposed to concatenating strings together, which is inefficient.
Member functions
append(self, value: string): self
Append a string to the builder.
clear(self): self
Clear the builder.
delete(self, start: number, end: number): self
Delete a range of characters from the builder from start
to end
(exclusive).
deleteAt(self, index: number): self
Delete a character from the builder at the specified index.
deleteLast(self, count: number): self
Delete the last count
characters from the builder.
size(self): number
Get the number of characters in the builder.
Metamethods
__index__(self, index: number): string
Get the character at the specified index.
__set__(self, index: number, value: string): self
Set the character at the specified index.
__str__(self): string
Get the string that the builder has built.