Re: converting unicode string "\uxxxx" to a single character

From: Jean-Marie Condom (jmc_at_meteorage.com)
Date: 06/11/04


Date: 11 Jun 2004 01:16:15 -0700

thanks for your answer
but I think that Gordon's solution is better
since method loadConvert gives effectively the result I need
immediatly, considering many cases (\r \t \u and so on) ;
I was looking for such a method but I didn't take
into consideration that I could find it in JDK source file!

Jean-Marie

Roedy Green <look-on@mindprod.com.invalid> wrote in message news:<hhogc01prq5hq1l1g0kmm1grgb1phe487p@4ax.com>...
> On 10 Jun 2004 05:53:31 -0700, jmc@meteorage.com (Jean-Marie Condom)
> wrote or quoted :
>
> >there is surely a solution since method load of class Properties
> >recognizes "\uxxxx" sequences and converts them to single characters
>
> The guts of it is pretty simple
>
> to convert "\uxxxx" to a char
>
> String hexString = s.substring( 2, 6 );
>
> int hex = Integer.parseInt(hexString, 16 /* radix */);
>
> char c = (char) hex;
>
>
> to find the \uxxxx patterns use a regex or use indexOf( "\\u" ) See
> http://mindprod.com/jgloss/regex.html