Split string function?

Moderator: Event DM

Post Reply
Croton
Team Member; Retired with Honors
Posts: 5950
Joined: Mon Jun 09, 2003 4:29 pm
Location: (-4 GMT - Summer)

Split string function?

Post by Croton » Sun Jan 04, 2009 2:12 am

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
User avatar
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?

Post by PsiOmega » Sun Jan 04, 2009 2:15 am

Gave the Lexicon a quick look and there doesn't appear to be any BioWare functions doing what you want.
Croton
Team Member; Retired with Honors
Posts: 5950
Joined: Mon Jun 09, 2003 4:29 pm
Location: (-4 GMT - Summer)

Re: Split string function?

Post by Croton » Sun Jan 04, 2009 2:34 am

Thanks as always Psi. I ended up just doing it the hard way with FindSubString, GetSubstring, and GetStringLength
User avatar
Nob
Lore Council Member
Lore Council Member
Posts: 7930
Joined: Mon Jun 30, 2003 1:19 am
DM Avatar: Dead but still a Dreamer

Re: Split string function?

Post by Nob » Sun Jan 04, 2009 5:32 am

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
User avatar
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?

Post by PsiOmega » Sun Jan 04, 2009 5:38 am

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;
}
Croton
Team Member; Retired with Honors
Posts: 5950
Joined: Mon Jun 09, 2003 4:29 pm
Location: (-4 GMT - Summer)

Re: Split string function?

Post by Croton » Sun Jan 04, 2009 6:46 am

Thanks Nob, thanks Psi!
User avatar
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?

Post by spool32 » Sun Jan 04, 2009 6:56 am

Split stri ng?

Split-p?

you can't split p without good kegels!



This makes sense to me...
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
Post Reply