mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2003
Posts: 18
M
Maveric Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Mar 2003
Posts: 18
I'm making a script that reads text from a socket and sometimes the text contains special characters that show up as Ô well I thought it would be simple to just change it to $chr(212) for the script so i wrote an alias.
Code:
 alias chrcheck {
  if ($1 != $null) {
    var %i = $replace($1-,&#, $chr(36) $+ chr $+ $chr(40), $chr(59) ,$chr(41) ) 
    return %i
  }
}

But no matter how I try to change it the alias either adds spaces around the character, or displays the identifier in the text.

Example:
Reads from the socket: Ôtsuka
After running through the alias I get:
$chr(212)tsuka OR with changes Ô tsuka
It should look like: Ôtsuka

I've spent too much time trying to fix it and it being 1:30am isn't helping. Any ideas?

Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Run the string though the following alias first, before you parse it wink

alias html_replace {
var %result = $1-, %regex = /(&#([0-9]+);)/
while ($regex(html, %result, %regex) > 0) { var %result = $replace(%result, $regml(html,1), $chr($regml(html,2))) }
return %result
}

Edit: Fixed it up a little wink

Last edited by KingTomato; 30/08/04 07:13 AM.

-KingTomato
Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
You were on the right track but needed to add $+ on either side of the $chr. The problem then is, what if the original string contained a space on one side of the special character? Quite a few checks are required. The following alias uses a regular expression to catch the position of these escaped special characters then evaluates them with $chr

alias crcheck {
;; Store our string in %f and expression in %re
var %f = $1-, $&
%re = /(&#( $+ \d{1,3} $+ )(;))
;; While special characters in &# format remain in the string, find their positions and replace them
while ($regex(%f,%re)) %f = $+($left(%f,$calc($regml(1).pos -1)),$chr($regml(2)),$mid(%f,$calc(1+$regml(3).pos)))
return %f
}

Edit; Sorry, was still typing when KingTomato posted. Can of course be shortened to %f = $replace(%f,$regml(1),$chr($regml(2)))

Joined: Mar 2003
Posts: 18
M
Maveric Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Mar 2003
Posts: 18
Thanks to both of you it works like a charm!


Link Copied to Clipboard