mIRC Homepage
Posted By: DaveC IF == comparing strings - 08/10/03 10:14 PM
im looking but cant find a operator that seems to work, maybe its staring me in the face, but i cant find it.

I want to compare two strings to see if they match, ok easy you say
if (%s1 == %s2) { or if (%s1 === %s2) {

problem appears when strings happen to contain values

%s1 = 0098
%s2 = 98

They match, im assuming mircs doing a numeric adjustment to them and saying the values the same.

So Is there a STRING== ?
Posted By: starbucks_mafia Re: IF == comparing strings - 08/10/03 10:22 PM
Just add a non-numeric character to both strings. ie. if ($+(a,%s1) == $+(a,%s2))
Posted By: codemastr Re: IF == comparing strings - 08/10/03 10:27 PM
No there isn't, but that certainly doesn't prevent you from making your own:
Code:
alias comparecs {
  var %c = 1, %d = 1

  while ($mid($1,%c,1) === $mid($2,%d,1) && $ifmatch) {
    inc %c
    inc %d
  }
  if ($mid($1,%c,1) === $mid($2,%d,1)) return $true
  return $false
}


$comparecs(0098,98) = $false
$comparecs(test,TEST) = $false
$comparecs(test,test) = $true

Posted By: DaveC Re: IF == comparing strings - 08/10/03 10:28 PM
hmmm thanks, so simple yet i didnt think of it, just got to caught up looking for operator to think about adjusting the strings
Posted By: Nobodi Re: IF == comparing strings - 09/10/03 09:58 AM
Could try $istok(%s1,%s2,32) .
Posted By: DaveC Re: IF == comparing strings - 10/10/03 05:27 AM
way to risky the strings might be
%s1 = bob the dog is here
%s2 = dog
Posted By: DaveC Re: IF == comparing strings - 10/10/03 05:30 AM
Just thought id say, I didnt even do it ascomplexly as "if ($+(a,%s1) == $+(a,%s2))" i just went
IF (x %s1 == x %s2)
© mIRC Discussion Forums