ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Thimotty on October 01, 2009, 01:35:13 PM
-
How can i change all spaces in a string with "_"
Somithing like:
set %prop #PROPERTY
while #spc in %prop
{
some actions with srt command and prop var
}
Can anyone help me?
-
Here's one I use:
;-------------------------------------------------------------------------------
; %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
-
wow too complex for me lol
here is my solution - just figured it :P
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
}
-
I like your way better!
-
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:
gosub strreplace #spc _ #PROPERTY
set %prop #RESULT
The SUB:
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
-
Gimme an idea of what this would be used for?
-
It's great for converting strings that you find in #JOURNAL or resulting strings from event property (#PROPERTY)
-
Gimme an idea of what this would be used for?
quick example:
finditem blablabla
event Property #FINDID
gosub strreplace #spc _ #PROPERTY
send HTTPPost mywebsite.com /test/test.php?var= , #RESULT
<?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
-
Just shows you .. thiers only so many ways to skin a cat.. My old sub contains remarkably simular code.
(Except less lines !!! hehe haha)
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
-
Yep i could lesser the lines with 2 and you with one :P
However my sub will replace any strings not only #spc
-
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 ;)
-
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.
-
haha TM you are trying to cheat :P
-
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. :)
-
That's better :P
We won't ban you this time :P :P :P
<off>
Transmitter is easy. He did build a teleporter :)
</off>