mIRC Home    About    Download    Register    News    Help

Print Thread
#229016 19/01/11 07:10 AM
Joined: Dec 2002
Posts: 254
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 254
ok well I ran into a problem where I needed to check if two strings matched identically but because their values were numerical, == and === were returning true. by design it's prolly NOT a bug but either way, incase anyone else runs into the issue i figured i'd mension it.

//echo -a $iif(001 == 01,t,f) -=- $iif(001 === 01,t,f)
result: t -=- t

solution: put a dot in front of it
//echo -a $iif(.001 == .01,t,f) -=- $iif(.001 === .01,t,f)
result: f -=- f

I know its a rare case, just happened to stumble upon it.. either way it might be a good idea to add some other form of === or something to take $v1 and $v2 as string literals and compare them rather than determining if the values are a string or a number.

since I was expecting padded numbers, i chose to place a dot in front to convert it from being padded to being a decimal, which makes the difference in how the if works. either way, this was all happening inside variables and took a minute to figure out why, if nothing else its a good read for anyone who may have had the same issue. since it was variables, it was $+(.,%var) == $+(.,%othervar) but i just made it simplistic to illustrate the problem I encountered.

Joined: Dec 2002
Posts: 344
D
Pan-dimensional mouse
Offline
Pan-dimensional mouse
D
Joined: Dec 2002
Posts: 344
Using a period (aka full stop) is an unfortunate choice because it would be interpreted as a decimal point. While it's true that the number .001 is not equal to the number .01, it is however true that .001 is equal to .0010.

The idea is sound, but you should use a different character to insert at the beginning of the text instead.

Joined: Jan 2011
Posts: 14
C
Pikka bird
Offline
Pikka bird
C
Joined: Jan 2011
Posts: 14
in bourne shell scripting, it's commonplace to prepend 'X' to any two values when you want to force string comparison.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
For a string comparison, that isn't a problem.
The situation shown is a comparison of two numerics, not strings.

As stated, .001 and .0010 will evaluate as the same, since mIRC will see these as numbers not strings.
To force them to be recognized as strings, you could prepend another character. I like to use quotation marks if there's any chance of confusion.

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
I'm confused, if you want to force them to be recognized as strings then csylvain's suggestion was perfectly fine.

FWIW I'm not really sure what the issue is here at all. If you want to compare numerics, then 001 *should* == 01 or 1. If you want to treat them as strings, prepending something like x is just fine:

//echo -a $iif(x 001 == x 01,t,f)


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
He said that prepending "X" to two values is used to force string comparison, i.e. force them to be compared as strings even if they are numbers.

That makes complete sense in this scenario.


Link Copied to Clipboard