Official ScriptUO EasyUO Scripts => Script Snippets => Topic started by: TrailMyx on March 16, 2009, 11:44:58 AM
Title: TrailMyx's Sub-String Subs
Post by: TrailMyx on March 16, 2009, 11:44:58 AM
Suppose you have delimited strings with a specific character:
Code: easyuo
set%SPELL28 ZTL#Greater_Heal#_GL_GS_MR_SS_#
And you want to access each of the substrings delimited by the "#" character. You can use the attached subs to access each one:
Code: easyuo
set%SPELL28 ZTL#Greater_Heal#_GL_GS_MR_SS_#
gosub TM_SplitString %SPELL28 #
gosub TM_SubstringCount
display ok Substrings found , #SPC , #RESULT
gosub TM_GetIndex 0
display ok Spell FINDTYPE , #SPC , #RESULT
gosub TM_GetIndex 1
display ok Spell Name , #SPC , #RESULT
gosub TM_GetIndex 2
display ok Spell reagents , #SPC , RESULT
stop
The subs:
Code: easyuo
;test code
eventproperty XXYYZZ1
gosub TM_SplitString #PROPERTY $
gosub TM_GetIndex 0
display ok #RESULT
stop
;end test code
sub TM_SplitString
namespacepush
namespacelocal PS
namespaceclear
set!string %1
set!delimiter %2
set!cnt0
strpos!string!delimiter
repeat
if#STRRES = 0
break
set!temp#STRRES - 1
strleft!string!temp
set!array . !cnt#STRRES
set!cnt!cnt + 1
set!temp!temp + 1
strdel!string1!temp
set!string#STRRES
strpos!string!delimiter
until#STRRES = 0
set#RESULT!cnt
namespacepop
return#RESULT
sub TM_GetIndex
namespacepush
namespacelocal PS
set!index %1
set#RESULT!array . !index
namespacepop
return#RESULT
sub TM_SubstringCount
namespacepush
namespacelocal PS
set#RESULT!cnt
namespacepop
return#RESULT
Just don't forget to end your string with your delimiter...
Title: Re: TrailMyx's Sub-String Subs
Post by: Cerveza on March 16, 2009, 12:04:44 PM
If I understood any of that I'm betting I'd say "WOW, thats some slick coding right there!"
Soooo.....
WOW, thats some slick coding right there! ;)
Title: Re: TrailMyx's Sub-String Subs
Post by: TrailMyx on March 16, 2009, 12:09:12 PM
heh, well thanks. Man, I wish I had a dollar for everytime I've basically implemented this same idea. I finally got around to do a generic one.
Actually, there's a cool twist to it I might post where the subs will store all the various splits. You'd reference it much like a 2 dimensional array.
Title: Re: TrailMyx's Sub-String Subs
Post by: Cerveza on March 16, 2009, 12:10:36 PM