mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2008
Posts: 11
Pikka bird
OP Offline
Pikka bird
Joined: Apr 2008
Posts: 11
Code:
%s = $+(%s,$chr(%c))

This will not work if %c is 32 (the ASCII code for space). How to make it work for any character code?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Technically it is working, however, since the last character in %s is the space character, mIRC automatically remove leading, multiple and trailing spaces, and has done so for as long as I've been using the program.


Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Only mIRC commands remove leading, trailing and multiple spaces (and even then there are a couple of exceptions). mIRC is able to handle multiple spaces fine in identifiers (including custom ones, if one uses /returnex instead of /return). For example, one can manipulate multiple spaces in a string and replace them with something else. This would not be possible if mIRC removed multiple spaces everywhere.

Variables can also store multiple/leading spaces fine - the only problem is when there is a single trailing space, in which case you can't put it in a variable. You can put two or more trailing spaces in a variable, but not a single one.

This is something that can be worked around though. A typical example is looping through a string char by char and appending each char to a variable. This will fail when parsing strings with spaces, but it can be worked around by just putting something else after the space, then removing it before using the var's value later. Compare this:
//var %s = hello world, %i = 1, %out | while $mid(%s,%i,1) != $null { var %out = %out $+ $v1 | inc %i } | echo -ag %out
(fails to preserve the space)
to this:
//var %s = hello world, %i = 1, %out | while $mid(%s,%i,1) != $null { var %out = $left(%out,-2) $+ $v1 Z | inc %i } | echo -ag $left(%out,-2)
(works)

The latter method is just appending " Z" (two chars) to the end of %out, then strips them out with $left(...,-2) before updating its value in the next iteration. It relies on the two facts I mentioned above, ie that both variables and identifiers can handle spaces in general.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I learned something new today, so the day hasn't been a total loss.

Joined: Apr 2008
Posts: 11
Pikka bird
OP Offline
Pikka bird
Joined: Apr 2008
Posts: 11
Thanks, qwerty. Funny how something that's a non-issue in almost every other scripting/programming language can be a problem in mIRC script.


Link Copied to Clipboard