Unrealscript splitting a string

Posted by burntsugar on Game Development See other posts from Game Development or by burntsugar
Published on 2013-10-11T02:10:36Z Indexed on 2013/11/10 10:18 UTC
Read the original article Hit count: 296

Filed under:

Note, this is repost from stackoverflow - I have only just discovered this site :)

I need to split a string in Unrealscript, in the same way that Java's split function works.

For instance - return the string "foo" as an array of char.

I have tried to use the SplitString function:

array SplitString( string Source, optional string Delimiter=",", optional bool bCullEmpty ) Wrapper for splitting a string into an array of strings using a single expression.

as found at http://udn.epicgames.com/Three/UnrealScriptFunctions.html but it returns the entire String.

simulated function wordDraw() {

local String inputString;
inputString = "trolls";
local string whatwillitbe;
local int b;
local int x;
local array<String> letterArray;

letterArray = SplitString(inputString,, false);
for (x = 0; x < letterArray.Length; x++)
{
        whatwillitbe = letterArray[x];
        `log('it will be '@whatwillitbe);
        b = letterarray.Length;
        `log('letterarray length is '@b);
        `log('letter number '@x);
}

}

Output is:

b returns:

1

whatwillitbe returns:

trolls

However I would like b to return 6 and whatwillitbe to return each character individually.

I have had a few answers proposed, however, I would still like to properly understand how the SplitString function works. For instance, if the Delimiter parameter is optional, what does the function use as a delimiter by default?

© Game Development or respective owner

Related posts about udk