Swift strcut
strcut(input,pattern) will match the regular expression in the pattern parameter against the supplied input string and return the section that matches the first matching parenthesised group.
For example:
string t = "my name is John and i like puppies.";
string name = strcut(t, "my name is ([^ ]*) ");
string out = strcat("Your name is ",name);
trace(out);
This will output the message: Your name is John.
strjoin
strjoin(array, delimiter) will combine the elements of an array into a single string separated by a given delimiter. The array passed to strjoin must be of a primitive type (string, int, float, or boolean). It will not join the contents of an array of files.
Example:
string test[] = ["this", "is", "a", "test" ];
string mystring = strjoin(test, " ");
tracef("%s\n", mystring);
This will print the string "this is a test".
strsplit
strsplit(input,pattern) will split the input string based on separators that match the given pattern and return a string array.
Example:
string t = "my name is John and i like puppies.";
string words[] = strsplit(t, "\\s");
foreach word in words {
trace(word);
}
This will output one word of the sentence on each line (though not necessarily in order, due to the fact that foreach iterations execute in parallel).
toInt
toInt(input) will parse its input string into an integer. This can be used with arg() to pass input parameters to a Swift script as integers.
toFloat
toFloat(input) will parse its input string into a floating point number. This can be used with arg() to pass input parameters to a Swift script as floating point numbers.
toString
toString(input) will parse its input into a string. Input can be an int, float, string, or boolean.