|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
Posted: Mon Dec 29, 2008 3:03 am
string stuff |
is there an easy way to take a string that came from the mud into a variable list ?
if %1 = a handful of rubies
can I add it to a list variable so that
list[1] = a
list[2] = handful
list[3] = of
list[4] = rubies
Thanks |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Dec 29, 2008 3:18 am |
Yep.
List = %replace(%1," ","|")
You could also use %subchar if you like. You can then use %item to get an item back out of the list, and #forall to iterate over the list. |
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
Posted: Mon Dec 29, 2008 4:30 am |
hummmm ... using this....
#additem aa %replace( %2, " ", "|")
#echo %item(@aa,1) produces
a|handful|of|rubies
It's not reading the | as seperators ? --maybe add an #eval ? |
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
Posted: Mon Dec 29, 2008 4:35 am |
Nevermind... :) Figured it out...
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon Dec 29, 2008 10:00 pm |
The reason it's not reading the | as separators is because you effectively added a stringlist to a stringlist, which results in nesting (the stringlist being added is automatically surrounded by parentheses.)
If you don't want nested stringlists, you either have to add each individual item separately or perhaps use %replace() or %remove() to pull the parentheses out after the additem. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
Posted: Mon Dec 29, 2008 10:04 pm |
reason I did it that way, I was reading the docs for #additem, it said #additem aa 1|2|3|4 would work correctly... or I misread it... anyway, it works now.
|
|
|
|
Progonoi Magician
Joined: 28 Jan 2007 Posts: 430
|
Posted: Mon Dec 29, 2008 10:24 pm |
Why not do
Code: |
#forall %replace(%2, " ", "|") {#additem aa %i}
|
instead? |
|
_________________ The Proud new owner of CMud.
--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
-------------------------------- |
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
Posted: Mon Dec 29, 2008 10:43 pm |
why loop, when you don't have to ?
List = %replace(%1," ","|") works just fine. |
|
|
|
Progonoi Magician
Joined: 28 Jan 2007 Posts: 430
|
Posted: Tue Dec 30, 2008 12:06 am |
ecourt wrote: |
hummmm ... using this....
#additem aa %replace( %2, " ", "|")
#echo %item(@aa,1) produces
a|handful|of|rubies
It's not reading the | as seperators ? --maybe add an #eval ?
|
Basically it was reply regarding this. My apologizes if I misunderstood. |
|
_________________ The Proud new owner of CMud.
--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
-------------------------------- |
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
Posted: Tue Dec 30, 2008 12:17 am |
no need for apologizes.. it's all good :D
|
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
|
|
|
calesta Apprentice
Joined: 07 Dec 2008 Posts: 102 Location: New Hampshire, USA
|
Posted: Sun Jan 04, 2009 3:40 pm |
The %replace actually works fine, its during the assignment that the expression on the right is evaluated where you lose the %20 I believe. I actually lose the &word when I try it as well since that is the Database character by default. Adding a ~ in front of the % and & worked for me:
Code: |
webadr = %replace(%replace(@webadr,"&","~&")," ","~%20") |
.
|
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
Posted: Sun Jan 04, 2009 3:47 pm |
thanks, I'll give it a shot...
|
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
|
|
|
calesta Apprentice
Joined: 07 Dec 2008 Posts: 102 Location: New Hampshire, USA
|
Posted: Sun Jan 04, 2009 6:39 pm |
You're doing a double assignment to webadr. Your first assignment puts the ~ in front of the & correctly. The second assignment with the %replace doesn't put the ~ back in front of the & (it was removed by the evaluation of the right side of the first assignment). If you do the double replace like I did in the example I posted before, that should fix the problem.
The reason it looks like it's skipping the word type is that the & makes zMUD think the following word is the name of a database variable. Since it's not, a null value ends up going in its place which makes it look like the word was skipped. |
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
Posted: Sun Jan 04, 2009 11:29 pm |
works the same with or without it.
tried it both ways. |
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
Posted: Sun Jan 04, 2009 11:43 pm |
even tried
Code: |
#var webadr 'www.web.com/add.php?name=@stuff.Name$type=@stuff.type
#echo -before- @webadr
webadr = %replace( %replace( @webadr, "$", "~&"), " ", "~%20")
#echo -after- @webadr
#url @webadr
|
which shows
-before- 'www.web.com/add.php?name=a golden sceptre$type=LIGHT
-after- 'www.web.com/add.php?name=a%20golden%20sceptre=LIGHT |
|
|
|
calesta Apprentice
Joined: 07 Dec 2008 Posts: 102 Location: New Hampshire, USA
|
Posted: Mon Jan 05, 2009 12:09 am |
Hrm, sorry. I forgot this was the zMUD thread and was testing it in CMUD where it works fine. I have the same problem with it that you're describing when doing it in zMUD and so far haven't figured out how to fix it.
|
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
Posted: Mon Jan 05, 2009 12:14 am |
I wish I could use cmud... it crashes so often it's unusable. started several threads, but no one has ever been able to help.
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Jan 05, 2009 1:08 am |
It just struck me, doubling up the & character might quote it. So try && instead.
|
|
|
|
calesta Apprentice
Joined: 07 Dec 2008 Posts: 102 Location: New Hampshire, USA
|
Posted: Mon Jan 05, 2009 1:28 am |
I just tried out that idea and it doesn't work either... you end up with this (note the missing 'type' after the &):
www.web.com/add.php?name=a%20golden%20sceptre&=LIGHT
If you're not using database variables you can go into preferences and turn off the database variable character on the special characters screen and it seems to work. You could also change the database character from & to something else I imagine... but that would involve changing any scripts you have that make use of the & database character plus you could mess others things up if you choose the new character badly... |
|
|
|
ecourt Apprentice
Joined: 29 Dec 2000 Posts: 146 Location: USA
|
Posted: Mon Jan 05, 2009 1:48 am |
I don't use any db stuff..the website I send the data to has a mysql back-end, and much better stuff :)
|
|
|
|
|
|