ScriptUO

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
  1. set %SPELL28 ZTL#Greater_Heal#_GL_GS_MR_SS_#
  2.  

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
  1. set %SPELL28 ZTL#Greater_Heal#_GL_GS_MR_SS_#
  2. gosub TM_SplitString %SPELL28 #
  3. gosub TM_SubstringCount
  4. display ok Substrings found , #SPC , #RESULT
  5. gosub TM_GetIndex 0
  6. display ok Spell FINDTYPE , #SPC , #RESULT
  7. gosub TM_GetIndex 1
  8. display ok Spell Name , #SPC , #RESULT
  9. gosub TM_GetIndex 2
  10. display ok Spell reagents , #SPC , RESULT
  11. stop
  12.  

The subs:
Code: easyuo
  1. ;test code
  2. event property XXYYZZ1
  3. gosub TM_SplitString #PROPERTY $
  4. gosub TM_GetIndex 0
  5. display ok #RESULT
  6. stop
  7. ;end test code
  8.  
  9. sub TM_SplitString
  10.   namespace push
  11.   namespace local PS
  12.   namespace clear
  13.   set !string %1
  14.   set !delimiter %2
  15.   set !cnt 0
  16.   str pos !string !delimiter
  17.   repeat
  18.     if #STRRES = 0
  19.       break
  20.     set !temp #STRRES - 1
  21.     str left !string !temp
  22.     set !array . !cnt #STRRES
  23.     set !cnt !cnt + 1
  24.     set !temp !temp + 1
  25.     str del !string 1 !temp
  26.     set !string #STRRES
  27.     str pos !string !delimiter
  28.   until #STRRES = 0
  29.   set #RESULT !cnt
  30.   namespace pop
  31. return #RESULT
  32.  
  33. sub TM_GetIndex
  34.   namespace push
  35.   namespace local PS
  36.   set !index %1
  37.   set #RESULT !array . !index
  38.   namespace pop
  39. return #RESULT
  40.  
  41. sub TM_SubstringCount
  42.   namespace push
  43.   namespace local PS
  44.   set #RESULT !cnt
  45.   namespace pop
  46. return #RESULT
  47.  


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
You'd reference it much like a 2 dimensional array.

So I'd need special glasses?
Title: Re: TrailMyx's Sub-String Subs
Post by: Endless Night on March 16, 2009, 06:23:56 PM
You'd reference it much like a 2 dimensional array.

So I'd need special glasses?

No .. you only need the glasses for the third dimensional array.

For the 4th dimensional array you need speacil underwear to maintain proper alignment with reality






ps nice code tm
Title: Re: TrailMyx's Sub-String Subs
Post by: TrailMyx on March 18, 2009, 11:45:19 AM

For the 4th dimensional array you need speacil underwear to maintain proper alignment with reality


Oh man, I just got a twinge of pain at the thought of a 4th dimensional Wedgie! 

Title: Re: TrailMyx's Sub-String Subs
Post by: Khameleon on March 18, 2009, 04:56:45 PM
those guys are hilarious.  Check out the ones with Tanya in them... she's as dumb as they come.