mIRC Home    About    Download    Register    News    Help

Print Thread
"isin" + Special chars #249960 24/12/14 11:31 AM
Joined: Aug 2014
Posts: 42
K
Krawalli Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Aug 2014
Posts: 42
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

Last edited by Krawalli; 24/12/14 11:31 AM.
Re: "isin" + Special chars [Re: Krawalli] #249961 24/12/14 12:16 PM
Joined: Feb 2011
Posts: 326
K
KindOne Offline
Fjord artisan
Offline
Fjord artisan
K
Joined: Feb 2011
Posts: 326
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 } 




irc.swiftirc.net #msl (mIRC Scripting Language)
Re: "isin" + Special chars [Re: Krawalli] #249963 24/12/14 12:24 PM
Joined: Sep 2014
Posts: 259
S
Sakana Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
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

Re: "isin" + Special chars [Re: Sakana] #249966 24/12/14 01:25 PM
Joined: Aug 2014
Posts: 42
K
Krawalli Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Aug 2014
Posts: 42
Thank you very much, is working fine!

Re: "isin" + Special chars [Re: Krawalli] #249969 24/12/14 10:39 PM
Joined: Feb 2003
Posts: 2,669
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,669
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.))


Well. At least I won lunch.
Good philosophy, see good in bad, I like!