mIRC Homepage
Posted By: Krawalli "isin" + Special chars - 24/12/14 11:31 AM
Hey 2 fast questions,
i want to forbid some special chars (not everyone!) in a script.


1. Question
What chars?
$ % and {

When i try:
if (($ isin $2-) || (% isin $2-) || ({ isin $2-)) { return } it dont work! smirk


2. Question
When i write:
if ($2- !isalnum) { return } the scripts returns when someone write something with spaces in it - how can i "fix" this? allow A-Z + 0-9 + Space?


Thank you for the informations smile
Posted By: KindOne Re: "isin" + Special chars - 24/12/14 12:16 PM
I can only answer one question off the top of my head.

Code:
; $chr(36) == $
; $chr(37) == %
; $chr(123) == {             
if (($chr(36) isin $2-) || ($chr(37) isin $2-) || ($chr(123) isin $2-)) { return }



If you like http://www.asciitable.com/index/asciifull.gif or you can find the $chr() for them on your own

Code:
//var %x 127 | while (%x) {  echo -ag %x - $chr(%x) | dec %x } 


Posted By: Sakana Re: "isin" + Special chars - 24/12/14 12:24 PM
That's probably because one or more of those characters are treated as operators/code and not normal characters. To make sure special characters are not evaluated as code, it's a good idea to use $chr.

You can find out what ascii number a character has by using $asc(charater).

Type this for example

//echo -a $asc($)


I'm not sure why $asc({) is not possible, but the number for is 123 anyways.

Code:
if ($chr(36) isin $2-) || ($chr(37) isin $2-) || ($chr(123) isin $2-) { return }


that should work
Posted By: Krawalli Re: "isin" + Special chars - 24/12/14 01:25 PM
Thank you very much, is working fine!
Posted By: Raccoon Re: "isin" + Special chars - 24/12/14 10:39 PM
Also, if you find yourself using a very long serious of if (x isin $2-) && (y isin $2-) && (z isin $2-) ..., you can achieve the same result with if ($count($1-,x,y,z)) or [/b]($countcs($1-,x,y,z))[/b].

You should also consider learning Regular Expressions which opens up a new world with $regex(), $regsub(), $regsubex().

if (!$regex($2-,/[A-Za-z0-9 ]/)) { return } is the equiv to the second question you asked. (though alphanum may also allow _ and - characters, so add them: /[A-Za-z0-9 _-]/)
((I don't need peanut gallery informing me of \w or /i, we're trying to ease him into regex.))
© mIRC Discussion Forums