Heres the code you're after, but please forgive its "quick and dirty"ness
as I threw it together in half an hour.
Its limitations are as follows.
1) Any data already in the 'Return' array is overwritten and/or lost and may be classified as a memory leak.
2) Hard-coded to be COMMA delimiters ONLY. (but you could change that yourself if you want to, it only appears on one line)
3) The 'Return' array does NOT get resized so if its was declared too big and you dont stop at the returned
index-count, or if it was initially declared too small, run-time errors MAY result (data dependant !!BAD!!).
4) If the source string ENDS with a comma, the last empty item will be ignored, so add a space after the comma
and it will be retained as a single space character string.
So this function will be useful if youve got a rough idea how many entries there will be. But unsafe to use of you
are reading unknown lengths of data(say from a externally generated file).
I'll post it as a starting point for others to work from.
So no usage rights are required.
Heres the routine itself
//
function StringSplit(STRING* *ReturnArray, STRING* SourceString)
{
if(str_len(SourceString)==0) { printf("StringSplit-->Invalid SourceData"); return; }
var ItemCount=0; var tmp;
STRING* TempData = str_create(SourceString);
//
while(str_len(TempData)>0) // Build Data Array
{
ReturnArray[ItemCount] = str_create(TempData); //Initialise THIS item
tmp = str_stri(TempData, ","); //Find Delimiter
if(tmp!=0)
{ str_trunc(ReturnArray[ItemCount], str_len(TempData) - tmp + 1); // Remove Delimiter and beyond from Item
str_clip(TempData, tmp); } // Remove "Used" TempData
else { str_cpy(TempData,""); }
if(str_len(TempData)>0) { ItemCount += 1; }
}
return(ItemCount+1);
}
//
And heres some code to show how its used and to see it in action, just open the ACKLOG.TXT when you've run the code.
...
STRING* ResultArray[50];
var Count = StringSplit(ResultArray,"Entry1,Entry2,Entry3,Entry4,Entry5,Entry6,Entry7,Entry8,Entry9,Entry10");
//
STRING* tmpStr = "#100";
diag("\n\nStringSplit Returned ");
diag(str_for_num(tmpStr,Count));
diag(" Entries.\n");
var cnt;
for (cnt=0; cnt<Count; cnt++)
{
diag(str_for_num(tmpStr,cnt)); diag("=\"");
diag(ResultArray[cnt]); diag("\"\n");
}
...
Enjoy!