mIRC Home    About    Download    Register    News    Help

Print Thread
#198852 05/05/08 01:37 PM
A
AWEstun
AWEstun
A
I tried to add a space to a string with:

var %abc = %abc $+ ,_

where _ is the space I want to add. How do I do this?

Joined: Jan 2003
Posts: 2,125
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,125
Unfortunately you cannot append a space to a variable, unless either
1. the variable already ends in a space (ie you can add a second trailing space, with %abc = %abc $+ $chr(32) )
or
2. the variable doesn't exist/is empty (so you can do var %abc = $chr(32) )

There various ways around this limitation. One of them is something like this:

var %abc = %abc $+ , Z

Z is just a dummy character. Next time you need to reference that variable, you can do it with $left(%abc,-1), which returns all but the rightmost character (Z here).

I'm pretty sure however that you can eliminate the need to append a space by rearranging your script suitably. For example in this case, I'm assuming you want to append a space so that later you can do something like %abc $+ two and have the result "one, two" (assuming %abc was initially "one, "). Instead of doing this however, you can append a single comma at first (%abc = %abc $+ ,) and later do %abc = %abc two. The end result would be the same.

Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
Alternatively, you can also use $addtok as long as you aren't going to have duplicate items in the list.

$addtok(%list,%new_item,44)

Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
I admit I'm guessing here, but my guess is that you want the output to look something like
Quote:
RusselB, AWEstun, XXX, xDaeMoN
if so, then use the $addtok suggestion (which will prevent the same name from occuring more than once), and when displaying the variable, use
Code:
msg $chan $replace(%abc,$chr(44),$+($chr(44),$chr(32)))
rather than
Code:
msg $chan %abc

The spaces won't actually be stored in the variable, but will be added at the proper locations when the variable is displayed in the channel (presuming that's how and where you're sending the contents of the variable)

A
AWEstun
AWEstun
A
Thanks.


Link Copied to Clipboard