Page 1 of 1
Split string function?
Posted: Sun Jan 04, 2009 2:12 am
by Croton
Is there a split string function? Meaning, if I take an item name with spaces, is there a way to break it into an array for every word?
I figure I could do it using the "FindSubString" function, to find the location of the space, then break the word apart before that, then do another FindSubString starting at the spot after the last space, but I was hoping there was an easier way.
Thanks,
Croton
Re: Split string function?
Posted: Sun Jan 04, 2009 2:15 am
by PsiOmega
Gave the Lexicon a quick look and there doesn't appear to be any BioWare functions doing what you want.
Re: Split string function?
Posted: Sun Jan 04, 2009 2:34 am
by Croton
Thanks as always Psi. I ended up just doing it the hard way with FindSubString, GetSubstring, and GetStringLength
Re: Split string function?
Posted: Sun Jan 04, 2009 5:32 am
by Nob
The proper one is ParseString.
Re: Split string function?
Posted: Sun Jan 04, 2009 5:38 am
by PsiOmega
Not a default function but here's a definition.
Code: Select all
#include "nw_o0_itemmaker"
int ParseString(string sString, string sSeperator, string sArray)
{
int iMarker = -1;
int iIndex = 0;
int iCount = 1;
string sLeft = "";
iMarker = FindSubString(sString, sSeperator);
while (iMarker != -1)
{
sLeft = GetStringLeft(sString, iMarker);
sString = GetStringRight(sString, GetStringLength(sString) - iMarker - 1);
SetLocalArrayString(OBJECT_SELF, sArray, iIndex, sLeft);
iIndex++;
iCount++;
iMarker = FindSubString(sString, sSeperator);
}
SetLocalArrayString(OBJECT_SELF, sArray, iIndex, sString);
return iCount;
}
Re: Split string function?
Posted: Sun Jan 04, 2009 6:46 am
by Croton
Thanks Nob, thanks Psi!
Re: Split string function?
Posted: Sun Jan 04, 2009 6:56 am
by spool32
Split stri ng?
Split-p?
you can't split p without good kegels!
This makes sense to me...