mIRC Home    About    Download    Register    News    Help

Print Thread
#200822 12/06/08 09:16 PM
Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
Hi there,
Just a quick question, is it possible to store a string in a variable that contains a space at the biginning and end of the string?
I ask because from what I can see the space at either end of the string seems to disappear?


Ninko

Last edited by Ninko; 12/06/08 09:16 PM.
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
You can at the beginning but not at the end:

//var %a = $+($chr(32),a,$chr(32)) | echo -ag $replace(%a,$chr(32),-)

($replace is used to replace any spaces in the variable with dashes. This way you can see exactly where %a contains spaces)

More precisely, you can't have a variable with a single trailing space that is preceded by a non-space character; oddly enough, you can have more than one trailing spaces:

//var %a = $+(a,$chr(32),$chr(32)) | echo -ag $replace(%a,$chr(32),-)

or a single space (and nothing else):

//var %a = $chr(32) | echo -ag $replace(%a,$chr(32),-)

There are ways around this limitation. One is to use padding: just append a dummy character (or N dummy characters) when you set the var, then use $left(%var,-N) to retrieve its value without the dummy chars:

//var %a = $+(test,$chr(32)) X | echo -ag $replace($left(%a,-2),$chr(32),-)

Here the string " X" (2 chars) is appended when %a is set. Then when it is used, $left() removes the last 2 chars.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
Thanks for the reply qwerty, I think I understand. Seems abit strange to me why those limits would be in place.

Take care


Ninko


Link Copied to Clipboard