|
l33t3rth4nur1111 Newbie
Joined: 29 May 2005 Posts: 6
|
Posted: Mon Jul 18, 2005 3:50 am
Simple function problem |
At least, it seems like one of those disgustingly simple problems.
I wrote a simple recursive function intended to take a string and return the string with an underscore before each character. For example,
Code: |
#EVA fnUnderString("123 456") |
should display
in the console. Here's my function:
Code: |
#FU fnUnderString {%if( %len( %1) = 0, "", %concat( "_", %left( %1, 1), @fnUnderString(%right(%1,1))))} |
The idea is to take the string and return the underscore, the first character, then the recursive call on the rest of the string.
For some reason, it works fine with most strings, but spaces are lost and some special characters (including the exclamation point) break it entirely. The above example produces
in the console.
It looks like a problem of evaluation--maybe the script sees " 456" without the leading space and ignores it. Can someone help me out? |
|
|
|
Aarlot Adept
Joined: 30 Dec 2003 Posts: 226
|
Posted: Mon Jul 18, 2005 4:59 am |
Well, don't know what to do about the spaces, but adding a couple %literal's to the function seems to make special characters work:
#FU fnUnderString {%if( %len( %1) = 0, "", %concat( "_", %left( %literal( %1), 1), @fnUnderString(%right(%literal(%1),1))))}
EDIT: though I just tested the original, and it didn't seem to have any problems with special chars anyway :p |
|
_________________ Everyone is entitled to their beliefs - until they die. Then only the truth matters. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Jul 18, 2005 9:57 pm |
The use of quotes would do it just fine. In fact I have said it many times, proper delimeter usage is required. In the case of what Aarlot said the %literal() make a delimeter.
#FU fnUnderString {%if( %len("%1") = 0, "", %concat( "_", %left( "%1", 1), @fnUnderString(%right("%1",1))))} |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
l33t3rth4nur1111 Newbie
Joined: 29 May 2005 Posts: 6
|
Posted: Wed Jul 20, 2005 3:25 am |
Thanks to you both; I'll give it a try and report the results.
|
|
|
|
l33t3rth4nur1111 Newbie
Joined: 29 May 2005 Posts: 6
|
Posted: Wed Jul 20, 2005 3:29 am |
Hmm, I tried both and I still got "_1_2_3_4_5_6" instead of the desired "_1_2_3_ _4_5_6".
Would any of my zMUD preferences affect the execution of these functions? (Other than changing special characters from the default, which I have not.) |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|