Aller au contenu


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 using tostring(). None
CoreString.Split(string s, [string delimiter], [table parameters]) ... Splits the string s into substrings separated by delimiter.
Optional parameters in the parameters table include:
removeEmptyResults (boolean): If true, empty strings will be removed from the results. Defaults to false.
maxResults (integer): Limits the number of strings that will be returned. The last result will be any remaining unsplit portion of s.
delimiters (string or Array<string>):Allows splitting on multiple delimiters. If both this and the delimiter parameter 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 to Split() in curly braces, eg: local myTable = {CoreString.Split("Hello Core!")}
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 from s instead of the default whitespace. For example, CoreString.Trim("(==((Hello!))==)", "(==(", ")==)") returns "(Hello!)". None
CoreString.IsProfane(string s) boolean Returns true if 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


Example using:



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.

-- 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)

-- Check the text entry value when text is being changed.

See also: UI.SetCanCursorInteractWithUI | script.GetCustomProperty | CoreObjectReference.WaitForObject | CoreLua.print | UITextEntry.text

Example using:



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
-- Join from a table
local sortedText = CoreString.Join(" ", table.unpack(words))
-- Output to Event Log

See also: CoreLua.print

Example using:


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, "!", " ")


See also: CoreLua.print

Dernière mise à jour: 6 octobre 2022