Skip to content

Instantly share code, notes, and snippets.

@trung
Created November 7, 2010 06:49
Show Gist options
  • Save trung/665987 to your computer and use it in GitHub Desktop.
Save trung/665987 to your computer and use it in GitHub Desktop.
Convert Unicode to Decimal NCR
use strict;
use utf8;
# convert unicode to Decimal NCR format
sub convertUnicodeToDecimalNCR {
my ($self, $str) = @_;
# important
utf8::decode($str);
my $ret_str = "";
while ($str =~ /(.)/g) {
my $c = $1;
my $b = ord($c);
if ($b > ord('z') && $b ne 123 && $b ne 125 && $b ne 126) {
$ret_str .= "&#".$b.";";
} else {
$ret_str .= $c;
}
}
# $str =~ s/./"&#".ord($&).";" if /eg;
return $ret_str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment