0

I am new to Java and have been battling this problem with google-fu ad experimentation for the last hour. I need to convert s1 to s2, where s1 and s2 are:

    String s1 ="\\u00C1";
    //...
    String s2 ="Á";
Val
  • 629
  • 1
  • 6
  • 12

2 Answers2

2

You need to scan the string to find the "\u" part, then extract the following four characters into a separate string, then use Integer.parseInt(String s, int radix) with a radix of 16 to convert 00C1 to an int, and then cast that int to char.

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
  • Thank you. I hoped for a shorter solution, like maybe using regex replacement functions. You really have to parse the string on character-by-character level, huh? – Val Jan 12 '12 at 03:03
  • I am afraid so. At least I do not know of any shorter solution. I mean, if there was a shortcut, I think that [those guys answering that question](http://stackoverflow.com/questions/53844/how-can-i-evaluate-a-c-sharp-expression-dynamically) a while ago would have mentioned it. – Mike Nakis Jan 12 '12 at 09:40
0
$ cat Test.java
public class Test {

    public static void main(String[] args) {
        String s = "\u00C1";
        System.out.println(s);
    }   
}

$ javac Test.java
$ java Test
Á

automatically

c00kiemon5ter
  • 16,994
  • 7
  • 46
  • 48