C++ Split function
by Bryan Stroebel · in Technical Issues · 05/23/2006 (12:35 pm) · 3 replies
Does Torque have split function I can use to split a string into a vector or array of strings? I thought i'd ask before writing one myself.
i want to do something like this
Vector myvec = Split(stringVariable,":"delimiter);
i want to do something like this
Vector
#2
The delimiter is an ';'
It takes a string called '%line' and your be left with an array called '%splitArray'.
remember to backslash your ';' that you don't want to split at.
05/23/2006 (9:14 pm)
Here you go have mine, should work but check it first because i riped it out of my game.The delimiter is an ';'
It takes a string called '%line' and your be left with an array called '%splitArray'.
remember to backslash your ';' that you don't want to split at.
%index = 0;
%splitString = "";
for (%a = 0; %a < strlen(%line); %a++) {
if (getSubStr(%line, %a, 1) $= "/") {
if (getSubStr(%line,%a + 1, 1) $= ";") {
%splitString = %splitString @ ";";
%a++;
}
} else if (getSubStr(%line,%a, 1) $= ";") {
if (getSubStr(%line,%a - 1, 1) !$= "/") {
%splitArray[%index] = splitString;
%index++;
%splitString = "";
}
} else {
%splitString = %splitString @ getSubStr(%line,%a, 1);
}
}
if (%splitString !$= "") {
%splitArray[%index] = splitString;
}
#3
05/24/2006 (7:31 am)
Thanks Paul.
Torque Owner Paul Griffiths