Skip to content
MSN

Need an expert!

A TG007 community discussion started by ronnie69.

Discussion 8 posts
Page 1 of 1
Open
Topic #5090 · 8 published posts · 739 views

I want a bit of code that checks whether individual characters match characters in a fixed string (either some or all of them and and case sensitive and in any order).

 

For example my fixed string is abcdef

 

Say someone types in the room...

 

!word afde

 

or

 

!word de

 

That would match true (as all those letters are in the string).

 

If they then typed...

 

!word afdv

 

or

 

!word av

 

It would match false as the v isnt in the string.

 

Also, just to further it, is there any way to show which letters do/dont match?

 

e.g if someone typed

 

!word xaftdbjc

 

it would say "correct letters are afdbc, incorrect letters are xtj"

 

 

Thanks for any help given!

Edited Oct 30, 2005 8:17 PM by ronnie69

in mIRC, type /help if then else

 

it would bring up a help file, there is loads of information there about it.

Thanks for the reply, I have done that but cannot find the information i require.

 

I have also looked for a long time via Google but cannot find a code that will do the above

 

Thats why i am asking here if anyone knows :)

 

 

Edited Oct 30, 2005 9:15 PM by ronnie69

$pos or $left & $right might be a little more useful :P

People are like slinkies; they're generally boring until you push them down stairs

would u not have to use regex to match strings?

Spam Honeypot - http://www.haggistech.co.uk/honey(humans do not register)

on *:text:!word &:#:{
 var %fixed = abcdef
 var %i = $len($2), %ok = $true, %match, %nomatch
 while (%i) {
   if ($mid($2,%i,1) isin %fixed) %match = $addtok(%match,$ifmatch,32)
   else { %ok = $false | %nomatch = $addtok(%nomatch,$ifmatch,32) }
   dec %i
 }  
 %match = $iif($remove(%match,$chr(32)) == $null, -none-, $ifmatch)
 %nomatch = $iif($remove(%nomatch,$chr(32)) == $null, -none-, $ifmatch)
 if (%ok) msg # all letters in $2 matched
 else msg # word $2 -> correct letters are: %match $+ , incorrect are: %nomatch
}

Hi, thanks Pete®tje thats great!

 

Couple of little things, ive changed the "isin" to "isincs" as i wanted it to be case sensitive but doesn't seem to work.

 

If my fixed variable is...

 

aAbBcCdDeEfF

 

and i enter...

 

!text aAbBcCdDeEfF

 

i get the "all letters in aAbBcCdDeEfF matched" response (which is great).

 

However if i make it so one or more are incorrect (add ZmM to the end), i get the following...

 

word aAbBcCdDeEfFZmM -> correct letters are: FEDCBA, incorrect are: MZ

 

For some reason it dropped all the lower case results?

 

Also, is it possible to return the correct/incorrect results in the same order as they were given.

 

e.g !text cCdDaAbBZmMeEfF would appear as...

 

word cCdDaAbBZmMeEfF -> correct letters are: cCdDaAbBeEfF, incorrect are: ZmM

 

Thanks once again :)

Different approach, lol.

on *:text:!word &:#:{

var %fixed = aAbBcCdDeEfF, %match, %nomatch, %s

%s = $regsub($2,/([ $+ %fixed $+ ]+)/g,,%nomatch)

%s = $regsub($2,/([ $+ %nomatch $+ ]+)/g,,%match)

if (!%nomatch) msg # all letters in $2 matched

elseif (!%match) msg # none of the letters in $2 matched

else msg # word: $2 -> correct letters are: %match $+ , incorrect are: %nomatch

}