ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Thimotty on October 01, 2009, 01:35:13 PM

Title: Help with string functions
Post by: Thimotty on October 01, 2009, 01:35:13 PM
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?
Title: Re: Help with string functions
Post by: TrailMyx on October 01, 2009, 01:38:02 PM
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
Title: Re: Help with string functions
Post by: Thimotty on October 01, 2009, 01:49:50 PM
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
     }
Title: Re: Help with string functions
Post by: TrailMyx on October 01, 2009, 01:50:47 PM
I like your way better!
Title: Re: Help with string functions
Post by: Thimotty on October 01, 2009, 02:15:57 PM
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
Title: Re: Help with string functions
Post by: Scrripty on October 01, 2009, 03:15:41 PM
Gimme an idea of what this would be used for?
Title: Re: Help with string functions
Post by: TrailMyx on October 01, 2009, 03:35:48 PM
It's great for converting strings that you find in #JOURNAL or resulting strings from event property (#PROPERTY)
Title: Re: Help with string functions
Post by: Thimotty on October 01, 2009, 03:42:47 PM
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
Title: Re: Help with string functions
Post by: Endless Night on October 02, 2009, 05:43:37 AM
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
Title: Re: Help with string functions
Post by: Thimotty on October 02, 2009, 09:03:35 AM
Yep i could lesser the lines with 2 and you with one :P
However my sub will replace any strings not only #spc
Title: Re: Help with string functions
Post by: Endless Night on October 02, 2009, 11:26:05 AM
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 ;)
Title: Re: Help with string functions
Post by: TrailMyx on October 02, 2009, 11:27:47 AM
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.
Title: Re: Help with string functions
Post by: Thimotty on October 02, 2009, 11:51:41 AM
haha TM you are trying to cheat :P
Title: Re: Help with string functions
Post by: TrailMyx on October 02, 2009, 11:53:48 AM
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.  :)
Title: Re: Help with string functions
Post by: Thimotty on October 02, 2009, 01:38:14 PM
That's better :P
We won't ban you this time :P :P :P
<off>
Transmitter is easy. He did build a teleporter :)
</off>