In Javascript, there are many methods to modify and manipulate strings. For example:
There is a ".split()" method that will separate the string by a character into an array. Like for example, when the you input "Hello: Strings are: Strings",split(":"), the output will be an array (call this array myArr) myArr[0] is "Hello", myArr[1] is " Strings are" and myArr[2] is " Strings".
Is there any way to manipulate strings in GUI triggers? Is there any built-in function or anything like that to it?
Like for instance, is there a sort of split() function that will split strings into an array like I have stated above?
There is no split function as far as I can tell. What you can do is loop through each character and check it against a condition (char_var == ":"), then use substring to save one portion of a string as another string variable.
You can easily write your own proper string split function by using my generic container library and using a vector as string buffer.
String split:
stringsplitOptions:ActionReturnType:(None)Parametersinputstring=""<String>delimeter=""<String>buffer=0<Integer>GrammarText:stringsplit(inputstring,delimeter,buffer)HintText:(None)CustomScriptCodeLocalVariablesinputlength=(Lengthofinputstring)<Integer>delimeterlength=(Lengthofdelimeter)<Integer>charid=1<Integer>extractfrom=1<Integer>ActionsGeneral-While(Conditions)aretrue,do(Actions)Conditionscharid<=inputlengthActionsGeneral-If(Conditions)thendo(Actions)elsedo(Actions)If(Substring(inputstring,charid,((charid+delimeterlength)-1)))==delimeterThen[Vector] Add (String)(buffer, (Substring(input string, extract from, (char id - 1))))
Variable - Set extract from = (char id + delimeter length)
Variable - Set char id = extract from
Else
Variable - Modify char id: + 1
[Vector] Add (String)(buffer, (Substring(input string, extract from, char id)))
Test trigger:
teststringsplitEventsGame-MapinitializationLocalVariablesmystring="this, is, a, test, 123."<String>stringbuffer=([Vector] Create()) <Integer>
i = 0 <Integer>
Conditions
Actions
string split(my string, ", ", string buffer)
General - For each integer i from 0 to ([Vector] Get Last Element ID(string buffer)) with increment 1, do (Actions)
Actions
Debug - Display (Combine ("'", (Text(([Vector] Get (String)(string buffer, i)))), "'")) as debug output using Type 01, and Do display it in the game window
[Vector] Destroy(string buffer)
In Javascript, there are many methods to modify and manipulate strings. For example:
There is a ".split()" method that will separate the string by a character into an array. Like for example, when the you input "Hello: Strings are: Strings",split(":"), the output will be an array (call this array myArr) myArr[0] is "Hello", myArr[1] is " Strings are" and myArr[2] is " Strings".
Is there any way to manipulate strings in GUI triggers? Is there any built-in function or anything like that to it?
Like for instance, is there a sort of split() function that will split strings into an array like I have stated above?
There is a normal substring(a,b) and something that takes the word(a) at index a. I wouldn't know of anything else
@Chris97Ong: Go
There is no split function as far as I can tell. What you can do is loop through each character and check it against a condition (char_var == ":"), then use substring to save one portion of a string as another string variable.
Just to do some shameless advertising here:
You can easily write your own proper string split function by using my generic container library and using a vector as string buffer.
String split:
Test trigger:
Debug output: