Author Topic: Help with string functions  (Read 4430 times)

0 Members and 1 Guest are viewing this topic.

Offline ThimottyTopic starter

  • Jr. Member
  • **
  • Posts: 61
  • Activity:
    0%
  • Reputation Power: 0
  • Thimotty has no influence.
  • Respect: +7
  • Referrals: 0
    • View Profile
Help with string functions
« on: October 01, 2009, 01:35:13 PM »
0
How can i change all spaces in a string with "_"
Somithing like:
Code: [Select]
set %prop #PROPERTY
while #spc in %prop
   {
   some actions with srt command and prop var
   }
Can anyone help me?

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13303
  • Activity:
    0.4%
  • Reputation Power: 154
  • 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: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Help with string functions
« Reply #1 on: October 01, 2009, 01:38:02 PM »
0
Here's one I use:

Code: [Select]
;-------------------------------------------------------------------------------
; %1 - string to mung
sub AddUnderscore
  namespace push
  namespace local AU
  set !tempstring %1
  AddUnderscore_loop1:
    str pos !tempstring #SPC
    if #STRRES <> 0
    {
      set !val #STRRES - 1
      str left !tempstring !val
      set !left #STRRES
      set !val !val + 1
      str del !tempstring 1 !val
      set !tempstring !left , _ , #STRRES
      goto AddUnderscore_loop1
    }
  set #RESULT !tempstring
  namespace pop
return #RESULT

The resulting string is returned in #RESULT
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline ThimottyTopic starter

  • Jr. Member
  • **
  • Posts: 61
  • Activity:
    0%
  • Reputation Power: 0
  • Thimotty has no influence.
  • Respect: +7
  • Referrals: 0
    • View Profile
Re: Help with string functions
« Reply #2 on: October 01, 2009, 01:49:50 PM »
0
wow too complex for me lol
here is my solution - just figured it :P

Code: [Select]
   set %prop #PROPERTY
   while #spc in %prop
      {
      STR POS %prop #spc
      set %position #STRRES
      STR DEL %prop %position 1
      set %prop #STRRES
      STR INS %prop _ %position
      set %prop #STRRES
     }

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13303
  • Activity:
    0.4%
  • Reputation Power: 154
  • 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: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Help with string functions
« Reply #3 on: October 01, 2009, 01:50:47 PM »
0
I like your way better!
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline ThimottyTopic starter

  • Jr. Member
  • **
  • Posts: 61
  • Activity:
    0%
  • Reputation Power: 0
  • Thimotty has no influence.
  • Respect: +7
  • Referrals: 0
    • View Profile
Re: Help with string functions
« Reply #4 on: October 01, 2009, 02:15:57 PM »
0
Syntax:
gosub strreplace {search string} {replace string} {string}


Description
Replace all occurrences of the {search string} in the {string} with the {replace string}. The result is stored in the #RESULT variable


Example:
Code: [Select]
gosub strreplace #spc _ #PROPERTY
set %prop #RESULT


The SUB:
Code: [Select]
sub strreplace
while %1 in %3
  {
  STR LEN %1
  set %search_len #STRRES
  STR POS %3 %1
  set %position #STRRES
  STR DEL %3 %position %search_len
  set %3 #STRRES
  STR INS %3 %2 %position
  set %3 #STRRES
  }
return %3

P.S.
TM if you like it you can move it in the Script Snippets forum :P
« Last Edit: October 01, 2009, 02:22:16 PM by Thimotty »

Scrripty

  • Guest
Re: Help with string functions
« Reply #5 on: October 01, 2009, 03:15:41 PM »
0
Gimme an idea of what this would be used for?

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13303
  • Activity:
    0.4%
  • Reputation Power: 154
  • 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: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Help with string functions
« Reply #6 on: October 01, 2009, 03:35:48 PM »
0
It's great for converting strings that you find in #JOURNAL or resulting strings from event property (#PROPERTY)
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline ThimottyTopic starter

  • Jr. Member
  • **
  • Posts: 61
  • Activity:
    0%
  • Reputation Power: 0
  • Thimotty has no influence.
  • Respect: +7
  • Referrals: 0
    • View Profile
Re: Help with string functions
« Reply #7 on: October 01, 2009, 03:42:47 PM »
0
Gimme an idea of what this would be used for?
quick example:

Code: [Select]
finditem blablabla
event Property #FINDID
gosub strreplace #spc _ #PROPERTY
send HTTPPost mywebsite.com /test/test.php?var= , #RESULT

Code: [Select]
<?PHP
$handle = fopen("test.txt", "a");
foreach($_GET as $key=>$val) {
fwrite($handle, $val);
fwrite($handle, "\n");
}
fclose($handle);
?>

i've got tired checking 30+ vendors when i need anything so i'm working on a script to create a database with all items by vendor :)

not planning something so fancy like searchuo but who knows.... :P
« Last Edit: October 01, 2009, 03:51:43 PM by Thimotty »

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Help with string functions
« Reply #8 on: October 02, 2009, 05:43:37 AM »
0
Just shows you .. thiers only so many ways to skin a cat.. My old sub contains remarkably simular code.
(Except less lines !!!  hehe haha)

Code: [Select]
sub MakeJournalString
  While #Spc in %1
    {
    str Pos %1 #spc
    set %Pos #strres
    str del %1 %Pos 1
    str Ins #StrRes _ %pos
    set %1 #StrRes
    }
Return %1
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 ThimottyTopic starter

  • Jr. Member
  • **
  • Posts: 61
  • Activity:
    0%
  • Reputation Power: 0
  • Thimotty has no influence.
  • Respect: +7
  • Referrals: 0
    • View Profile
Re: Help with string functions
« Reply #9 on: October 02, 2009, 09:03:35 AM »
0
Yep i could lesser the lines with 2 and you with one :P
However my sub will replace any strings not only #spc

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Help with string functions
« Reply #10 on: October 02, 2009, 11:26:05 AM »
0
Yep i could lesser the lines with 2 and you with one :P
However my sub will replace any strings not only #spc

Yes that is a nice advancement. Score Thimotty -2  EN - 1 TM - 0 .. ow tm what happened LOL ;)
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 TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13303
  • Activity:
    0.4%
  • Reputation Power: 154
  • 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: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Help with string functions
« Reply #11 on: October 02, 2009, 11:27:47 AM »
0
Yep i could lesser the lines with 2 and you with one :P
However my sub will replace any strings not only #spc

Yes that is a nice advancement. Score Thimotty -2  EN - 1 TM - 0 .. ow tm what happened LOL ;)

heh, well that was some code modified from the 1.42 days.  No fancy whiles back then.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline ThimottyTopic starter

  • Jr. Member
  • **
  • Posts: 61
  • Activity:
    0%
  • Reputation Power: 0
  • Thimotty has no influence.
  • Respect: +7
  • Referrals: 0
    • View Profile
Re: Help with string functions
« Reply #12 on: October 02, 2009, 11:51:41 AM »
0
haha TM you are trying to cheat :P

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13303
  • Activity:
    0.4%
  • Reputation Power: 154
  • 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: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Help with string functions
« Reply #13 on: October 02, 2009, 11:53:48 AM »
0
haha TM you are trying to cheat :P

Hey, if Spock can make a sub-space transmitter with stone knives and bear skins, I can certainly make a loop with GOTOs.  :)
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline ThimottyTopic starter

  • Jr. Member
  • **
  • Posts: 61
  • Activity:
    0%
  • Reputation Power: 0
  • Thimotty has no influence.
  • Respect: +7
  • Referrals: 0
    • View Profile
Re: Help with string functions
« Reply #14 on: October 02, 2009, 01:38:14 PM »
0
That's better :P
We won't ban you this time :P :P :P
<off>
Transmitter is easy. He did build a teleporter :)
</off>
« Last Edit: October 02, 2009, 01:41:15 PM by Thimotty »

Tags: