mIRC Home    About    Download    Register    News    Help

Topic Options
#52991 - 08/10/03 11:14 PM IF == comparing strings
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
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== ?

Top
#52992 - 08/10/03 11:22 PM Re: IF == comparing strings
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
Just add a non-numeric character to both strings. ie. if ($+(a,%s1) == $+(a,%s2))
_________________________
Spelling mistakes, grammatical errors, and stupid comments are intentional.

Top
#52993 - 08/10/03 11:27 PM Re: IF == comparing strings
codemastr Offline
Hoopy frood

Registered: 12/12/02
Posts: 2809
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


Top
#52994 - 08/10/03 11:28 PM Re: IF == comparing strings
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
hmmm thanks, so simple yet i didnt think of it, just got to caught up looking for operator to think about adjusting the strings

Top
#52995 - 09/10/03 10:58 AM Re: IF == comparing strings
Nobodi Offline
Vogon poet

Registered: 10/12/02
Posts: 191
Loc: Australia
Could try $istok(%s1,%s2,32) .

Top
#52996 - 10/10/03 06:27 AM Re: IF == comparing strings
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
way to risky the strings might be
%s1 = bob the dog is here
%s2 = dog

Top
#52997 - 10/10/03 06:30 AM Re: IF == comparing strings
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
Just thought id say, I didnt even do it ascomplexly as "if ($+(a,%s1) == $+(a,%s2))" i just went
IF (x %s1 == x %s2)

Top