Author Topic: Splitting a String  (Read 617 times)

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

%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);
}


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

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

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

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

Is there a way that I can get the first word as one variable and the rest of the string as another?

If so, How?

%var1 = getWord(original string, 0);
%rest = getwords(original string, 1, getWordCount(original string)-1);