Server Totals
Le'Or - (1)
Elysia - (0)
Deglos - (0)
Ferrell - (0)
M'Chek - (0)
Mikona - (0)
Wilderness - (0)
Visimontium - (0)
Underdark - (0)
Total players: 1
Gallery

Links Menu

Split string function?

Moderators: Nighthawk4, Dungeon Masters

Split string function?

PostAuthor: 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

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

Re: Split string function?

PostAuthor: 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.
User avatar
PsiOmega
CCC
CCC
 
Posts: 4901
Joined: Tue Jun 08, 2004 4:55 pm
Location: Sweden
Timezone: GMT+1/+2 (DST)

Re: Split string function?

PostAuthor: 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

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

Re: Split string function?

PostAuthor: 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
Nob
Elder DM
Elder DM
 
Posts: 7630
Joined: Mon Jun 30, 2003 1:19 am
DM Avatar: Dead but still a Dreamer

Re: Split string function?

PostAuthor: 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;
}
User avatar
PsiOmega
CCC
CCC
 
Posts: 4901
Joined: Tue Jun 08, 2004 4:55 pm
Location: Sweden
Timezone: GMT+1/+2 (DST)

Re: Split string function?

PostAuthor: Croton » Sun Jan 04, 2009 6:46 am

Thanks Nob, thanks Psi!

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

Re: Split string function?

PostAuthor: 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
User avatar
spool32
Team Member; Retired with Honors
 
Posts: 13283
Joined: Sun Dec 12, 2004 6:12 pm
Location: Austin, TX
Timezone: GMT -6


Return to NWN Scripting

Who is online

Registered users: Bing [Bot], Google [Bot]