Blockland Forums > Modification Help

Splitting a String

Pages: (1/2) > >>

Fluff-is-back:

Hi,

How can I go about splitting a string of text at a apace into two strings?
for example:
original string = text1 text2
into
%str1 = text1
%str2 = text2

Chrono:

%str0 = getWord(original string,0);
%str1 = getWord(original string,1);

Or for a loop  to get all of it

for(%x=0;%x<getWordCount(original string);%x++)
{
%str[%x] = getWord(original string,%x);
}

Fluff-is-back:

Thanks

lilboarder32:

Chrono's code splits the words up in a string. If you want to split it at any spot, use this:


--- Code: ---%str0 = getSubStr(%sourceString,%startingPosition,%lengthOfCut);
%str1 = getSubStr(%sourceString,%startingPosition + %lengthOfCut, strLen(%sourceString));

--- End code ---

%startingPosition starts at 0 (i.e. If you had a string "Hello World", The "H" would be at 0, the space would be at 5.)

Chrono:


--- Quote from: Fluff-is-back on November 29, 2010, 12:11:44 PM ---Hi,

How can I go about splitting a string of text at a apace into two strings?
for example:
original string = text1 text2
into
%str1 = text1
%str2 = text2

--- End quote ---


Pages: (1/2) > >>

Go to full version