Author Topic: TrailMyx's Sub-String Subs  (Read 2677 times)

0 Members and 1 Guest are viewing this topic.

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12909
  • Activity:
    0.4%
  • Reputation Power: 149
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1328
  • Referrals: 32
    • View Profile
    • ScriptUO
TrailMyx's Sub-String Subs
« on: March 16, 2009, 11:44:58 AM »
0
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...
« Last Edit: May 05, 2017, 05:03:53 PM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: TrailMyx's Sub-String Subs
« Reply #1 on: March 16, 2009, 12:04:44 PM »
0
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!  ;)
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12909
  • Activity:
    0.4%
  • Reputation Power: 149
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1328
  • Referrals: 32
    • View Profile
    • ScriptUO
Re: TrailMyx's Sub-String Subs
« Reply #2 on: March 16, 2009, 12:09:12 PM »
0
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.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: TrailMyx's Sub-String Subs
« Reply #3 on: March 16, 2009, 12:10:36 PM »
0
You'd reference it much like a 2 dimensional array.

So I'd need special glasses?
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5264
  • Activity:
    0%
  • Reputation Power: 59
  • Endless Night is leading the good life!Endless Night is leading the good life!Endless Night is leading the good life!Endless Night is leading the good life!Endless Night is leading the good life!Endless Night is leading the good life!Endless Night is leading the good life!Endless Night is leading the good life!Endless Night is leading the good life!Endless Night is leading the good life!Endless Night is leading the good life!
  • Respect: +386
  • Referrals: 1
    • View Profile
Re: TrailMyx's Sub-String Subs
« Reply #4 on: March 16, 2009, 06:23:56 PM »
0
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
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12909
  • Activity:
    0.4%
  • Reputation Power: 149
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1328
  • Referrals: 32
    • View Profile
    • ScriptUO
Re: TrailMyx's Sub-String Subs
« Reply #5 on: March 18, 2009, 11:45:19 AM »
0

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! 

« Last Edit: March 18, 2009, 11:48:57 AM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Khameleon

  • Script Tester - Team Leader
  • Elite
  • *
  • *
  • Posts: 2568
  • Activity:
    0%
  • Reputation Power: 30
  • Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!
  • Gender: Male
  • Respect: +237
  • Referrals: 0
    • View Profile
Re: TrailMyx's Sub-String Subs
« Reply #6 on: March 18, 2009, 04:56:45 PM »
0
those guys are hilarious.  Check out the ones with Tanya in them... she's as dumb as they come.