Split string function?
Moderator: Event DM
-
- Team Member; Retired with Honors
- Posts: 5950
- Joined: Mon Jun 09, 2003 4:29 pm
- Location: (-4 GMT - Summer)
Split string function?
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
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
- PsiOmega
- Team Member; Retired with Honors
- Posts: 4886
- Joined: Tue Jun 08, 2004 4:55 pm
- Timezone: GMT+1/+2 (DST)
- Location: Sweden
Re: Split string function?
Gave the Lexicon a quick look and there doesn't appear to be any BioWare functions doing what you want.
-
- Team Member; Retired with Honors
- Posts: 5950
- Joined: Mon Jun 09, 2003 4:29 pm
- Location: (-4 GMT - Summer)
Re: Split string function?
Thanks as always Psi. I ended up just doing it the hard way with FindSubString, GetSubstring, and GetStringLength
- Nob
- Lore Council Member
- Posts: 7930
- Joined: Mon Jun 30, 2003 1:19 am
- DM Avatar: Dead but still a Dreamer
Re: Split string function?
The proper one is ParseString.
"Andrinor grant me the patience not to kill those who screw things up through stupidity, the power to incinerate those who screw things up on purpose, and the wisdom to distinguish between one and the other." -The War Mage's Serenity Prayer
- PsiOmega
- Team Member; Retired with Honors
- Posts: 4886
- Joined: Tue Jun 08, 2004 4:55 pm
- Timezone: GMT+1/+2 (DST)
- Location: Sweden
Re: Split string function?
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;
}
-
- Team Member; Retired with Honors
- Posts: 5950
- Joined: Mon Jun 09, 2003 4:29 pm
- Location: (-4 GMT - Summer)
Re: Split string function?
Thanks Nob, thanks Psi!
- spool32
- Team Member; Retired with Honors
- Posts: 13280
- Joined: Sun Dec 12, 2004 6:12 pm
- Timezone: GMT -6
- Location: Austin, TX
Re: Split string function?
Success will be lovely, but you will have to go out and get it! Failure will invite itself in.
Your donation makes this sig possible!
Monthly donations help you Lose Weight Fast!
DM 101
Your donation makes this sig possible!
Monthly donations help you Lose Weight Fast!
DM 101