I needed a simple script that converted multiple CHR and ASCII codes.
Syntax
/char
/ascii
V2 UPDATE**
I didn't want to change without first understanding regex, but now that I do (mostly), I want to make this script a bit more efficient. So I'm changing this to regex format. A thanks to sunslayer for pushing me towards learning regex, even thought it was unintentional.
alias ascii { echo -a 07ASCII: $regsubex($1-,/(.)/g,$+($iif(\n == 1,$+(07,$chr(91),)),$chr(32),$!asc,$chr(40),\t,$chr(41) = $asc(\t) $iif(\n != \0,$+(07,$chr(93),$chr(91),),$+(07,$chr(93),)))) }
alias char { echo -a 07CHR: $regsubex($1-,/(\d+)(?=(?:\W)+|.*)/g,$+($iif(\n == 1,$+(07,$chr(91),)),$chr(32),$!chr,$chr(40),\t,$chr(41) = $chr(\t) $iif(\n != \0,$+(07,$chr(93),$chr(91),),$+(07,$chr(93),)))) }
Other than regex, you can also use mirc's binary variables to accomplish:
alias char {
if (!$1) { echo -a * Enter a number: e.g. /char <numbers> }
else { bset &b 1 $1- | echo -a $+(CHR,:,$chr(32),$bvar(&b,1-).text) }
}
alias ascii {
if (!$1) { echo -a * Enter a character: e.g. /ascii <characters> }
else { bset &b 1 $1- | echo -a $+(ASCII,:,$chr(32),$bvar(&b,1-).nword) }
}
P.S. I think sunslayer has those two aliases reversed, where the ascii one should be the char one, and vice versa.
-Edited added a check.
@Testor $addtok will only work if the token doesn't already exist, you can use $instok but using regex is much faster and simpler
alias ascii { echo -a 7CHR: $regsubex($1-,/(.)/g,$+($!chr,$chr(40),\t,$chr(41) = $asc(\t) $iif(\n != \0,$chr(44)))) }
alias char { echo -a 07ASCII: $regsubex($1-,/(\d+)(?=(?:\W)+|.*)/g,$+($!asc,$chr(40),\t,$chr(41) = $chr(\t) $iif(\n != \0,$chr(44)))) }