CoreString
The CoreString namespace contains a set of string utility functions.
Class Functions
| Class Function Name | Return Type | Description | Tags | 
|---|---|---|---|
| CoreString.Join(string delimiter, [...]) | string | Concatenates the given values together, separated by delimiter. If a given value is not a string, it is converted to one usingtostring(). | None | 
| CoreString.Split(string s, [string delimiter], [table parameters]) | ... | Splits the string sinto substrings separated bydelimiter.Optional parameters in the parameterstable include:removeEmptyResults (boolean): Iftrue, empty strings will be removed from the results. Defaults tofalse.maxResults (integer): Limits the number of strings that will be returned. The last result will be any remaining unsplit portion ofs.delimiters (string or Array<string>):Allows splitting on multiple delimiters. If both this and thedelimiterparameter are specified, the combined list is used. If neither is specified, default is to split on any whitespace characters.Note that this function does not return a table, it returns multiple strings. For example: local myHello, myCore = CoreString.Split("Hello Core!")If a table is desired, wrap the call toSplit()in curly braces, eg:local myTable = {CoreString.Split("Hello Core!")} | None | 
| CoreString.Trim(string s, [...]) | string | Trims whitespace from the start and end of s, returning the result. An optional list of strings may be provided to trim those strings fromsinstead of the default whitespace. For example,CoreString.Trim("(==((Hello!))==)", "(==(", ")==)")returns "(Hello!)". | None | 
| CoreString.IsProfane(string s) | boolean | Returns trueif the given string contains profanity. | Client-Only | 
| CoreString.FilterProfanity(string s) | string | Replaces any profanity that may be contained in the given string and returns the result. | Client-Only | 
Examples
Example using:
IsProfane
 FilterProfanity
 In this example we check if the text the player is entering into a text entry box contains profanity. If the text does contain profanity, then a print to the Event Log is done, and using the FilterProfanity function, we can remove any words that are considered to be Profanity with asterisk characters.
-- Client Script
local TEXT_ENTRY_BOX = script:GetCustomProperty("UITextEntryBox"):WaitForObject()
-- Turn on the cursor so focusing of the text entry box can be done by the player.
UI.SetCanCursorInteractWithUI(true)
UI.SetCursorVisible(true)
-- When the text has changed, this function will run everytime and filter out
-- any profanity.
function CheckProfanity(obj, txt)
    if(CoreString.IsProfane(txt)) then
        print("Text contains profanity")
        TEXT_ENTRY_BOX.text = CoreString.FilterProfanity(txt)
    end
end
-- Check the text entry value when text is being changed.
TEXT_ENTRY_BOX.textChangedEvent:Connect(CheckProfanity)
See also: UI.SetCanCursorInteractWithUI | script.GetCustomProperty | CoreObjectReference.WaitForObject | CoreLua.print | UITextEntry.text
Example using:
Split
 Join
 In this example, the words in a sentence are sorted into alphabetical order.
local text = "the quick brown fox jumps over the lazy dog."
-- Split into a table
local words = {
    CoreString.Split(text, {
        delimiters = {" ", "."},
        removeEmptyResults = true
    })
}
-- Sort the table
table.sort(words)
-- Join from a table
local sortedText = CoreString.Join(" ", table.unpack(words))
-- Output to Event Log
print(text)
print(sortedText)
See also: CoreLua.print
Example using:
Trim
 In this example we look at different ways to use the Trim() function to eliminate symbols from the beginning and end of a string. Results are printed to the Event Log.
local original = "  Hello World!!!"
local trimmed1 = CoreString.Trim(original)
local trimmed2 = CoreString.Trim(original, "!", " ")
print(original)
print(trimmed1)
print(trimmed2)
See also: CoreLua.print