LPM: java ?
Joe Hourcle
oneiros at dcr.net
Mon May 1 08:11:07 CDT 2000
On Fri, 28 Apr 2000 repett0 at sac.uky.edu wrote:
>
> I know this is perl, but since perl has a nice easy way to do this, Im
> hoping someone knows the java way to do this.
>
> 1) convert a char into an int
> 2) convert a string into an int
I don't know what you'd constitute as a string into an int, but the char
one is easy --
unpack('C', $char);
If you're trying to do something like URI encode a string, this will do
it:
sub encode {
$_ = shift(@_);
s/(\W)/sprintf('%%%02X',unpack('C',$1))/eg;
return $_;
}
And, to do things the other way, use pack. eg, this will get rid of URI
encoding:
sub decode {
$_ = shift(@_);
$_ =~ tr/+/ /;
$_ =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack('C', hex($1))/eg;
return $_;
}
-----
Joe Hourcle
More information about the Lexington-pm
mailing list