$char

Platform:  mIRC
Published  Dec 23, 2007
Updated  Dec 23, 2007
See comments below /*
** $char
* snippet made by opticlens

** Basically being $chr and $asc for multiple input, with more options.

* $char(<asc|chr>,<string seperated by commas>)[.se]
* <asc> will return an $asc version of the string
* <chr> will return the $chr version of the string
* <string> must be seperated by commas if you want multiple results
* [.s] prop: returns the output in a $+(<string>) format

* [.e] prop will format each output in a $chr(<token>) or
$asc(<token>) format [returns in $asc format for chr and $chr format for asc (see below)]

* [.se] props will format each output in a $+($chr/asc(<token>) format. [.se doesn't have to be exact due to iswm (e.g it could be .es)]

** EXAMPLES:
* USING chr:

* $char(chr,43,45,47) returns +,-,/
* $char(chr,43,45,47).s returns $+(+,-,/)
* $char(chr,43,45,47).e returns $asc(+),$asc(-),$asc(/)
* $char(chr,43,45,47).se returns $+($asc(+),$asc(-),$asc(/))

* USING asc:

* $char(asc,+,-,/) returns 43,45,47
* $char(asc,+,-,/).s returns $+(43,45,47)
* $char(asc,+,-,/).e returns $chr(43),$chr(45),$chr(47)
* $char(asc,+,-,/).se returns $+($chr(43),$chr(45),$chr(47))
*/

alias char {
var %ž = !echo -ac info * $!char
if (!$isid) %ž ERROR_SYNTAX: Must be an identifier
elseif ($2-) {
if ($1 == chr) || ($1 == asc) {
var %x = 2, %•
while (%x <= $0) {
var %o = $($ $+ %x,2)

if (%o isnum 1-255) && ($1 == chr) %• = $+(%•, $&
$iif(%x != 2,$chr(44)),$iif($prop && *e* iswm $&
$prop,$+($!asc,$chr(40),$chr(%o),$chr(41)),$chr(%o)))

else %• = $+(%•,$iif(%x != 2,$chr(44)),$iif($prop && $&
*e* iswm $&
$prop,$+($!chr,$chr(40),$asc(%o),$chr(41)),$asc(%o)))

inc %x
}
return $iif(*s* iswm $prop,$+($!+,$chr(40),%•,$chr(41)),%•)
}
else %ž ERROR_SYNTAX: Properties must be either $+(,chr,) or $+(,asc,)
}
elseif ($1) && (!$2-) %ž NO_PARAMS: There is no input to modify.
else %ž NO_PARAMS
halt
}

Comments

Sign in to comment.
sunburst   -  Dec 25, 2007
Agh, and replace /(d+)/g with /([backslash]d+)/g :X
 Respond  
sunburst   -  Dec 25, 2007
Just replace $asc(1) and $chr(1) with $chr(backslash1) and $asc(backslash1)
 Respond  
sunburst   -  Dec 25, 2007
I think using $regsubex would be better in this case. Here is an updated version of the code:

Code

 

Same syntax and all, just uses $regsubex.
 Respond  
Rebellious   -  Dec 23, 2007
Very nice job on this.
 Respond  
opticlens   -  Dec 23, 2007
comments, rants, criticism?
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.