Extensions String
scripts/vscripts/alyxlib/extensions/string.lua
Methods
startswith
Checks if a string starts with a substring.
Parameters
s
string
The string to checksubstr
string
The substring to check
Returns
- boolean
true if the string starts with the substring, false otherwise
endswith
Checks if a string ends with a substring.
Parameters
s
string
The string to checksubstr
string
The substring to check
Returns
- boolean
true if the string ends with the substring, false otherwise
splitraw
Splits a string using a raw pattern string. No changes are made to the pattern.
Parameters
s
string
String to split.pattern
string
Split pattern
Returns
- string[]
Array of split strings
split
Splits a string using a separator string.
If sep is omitted, splits on whitespace (%s).
Uses Lua pattern matching; escape special characters if needed.
Parameters
s
string
String to splitsep
string?
String to split by
Returns
- string[]
Array of split strings
truncate
Truncates a string to a maximum length.
If the string is shorter than len the original string is returned.
Parameters
s
string
String to truncatelen
integer
Maximum length the string can bereplacement(optional)
string
Suffix for long strings. Default is...
Returns
- string
The truncated string
sliceleft
Slices the string from the left, returning everything after the last occurrence of a specified character.
Parameters
s
string
The string to slicechar
string
The character to trim the string at the last occurrence
Returns
- string
The trimmed string
sliceright
Slices the string from the right, returning everything before the first occurrence of a specified character.
Parameters
s
string
The string to slicechar
string
The character to trim the string at the last occurrence
Returns
- string
The trimmed string
trimleft
Trims characters from the left side of a string.
Parameters
s
string
String to trimchars(optional)
string
Characters to trim (defaults to whitespace)
Returns
- string
The trimmed string
trimright
Trims characters from the right side of a string.
Parameters
s
string
String to trimchars(optional)
string
Characters to trim (defaults to whitespace)
Returns
- string
The trimmed string
capitalize
Capitalizes letters in the input string.
If onlyFirstLetter is true, it capitalizes only the first letter.
If onlyFirstLetter is false or not provided, it capitalizes all letters.
Parameters
s
string
The string to be capitalizedonlyFirstLetter(optional)
boolean
If true, only the first letter is capitalized
Returns
- string
The capitalized string