Search code examples
javaandroidequivalent

ChrW and AscW equivalent in Java (with Android SDK)


I need the function that return the Ascii code (actually Unicode number code), as well as convert that code to the Unicode character one. They are ChrW and AscW in .NET. Ex: AscW("A") is 65, ChrW(65) is A.

Thanks.


Solution

  • Actually, those are from VB.NET, not actually the .NET Framework.

    In Java a char is sort of a integral type. You can convert it to int and back:

    String s = "abc";
    char a = s.charAt(0);
    int a_codepoint = (int)a;
    
    char x = (char)120;