Sunday, January 26, 2014

How to determine the Unicode code of a String?

Source:
public class StringUniCode {
   public static void main(String args[]){
      String str="abcd EFGH 1234";
      System.out.println( str );
      for (int i=0; i<str.length(); i++ ) {
         System.out.println("Unicode for " + str.charAt(i) + " : " + str.codePointAt(i));
      }
   }
}

Output:
   $ java StringUniCode 
   abcd EFGH 1234
   Unicode for a : 97
   Unicode for b : 98
   Unicode for c : 99
   Unicode for d : 100
   Unicode for   : 32
   Unicode for E : 69
   Unicode for F : 70
   Unicode for G : 71
   Unicode for H : 72
   Unicode for   : 32
   Unicode for 1 : 49
   Unicode for 2 : 50
   Unicode for 3 : 51
   Unicode for 4 : 52


Another example can be found here: http://javacodex.com/Strings/Get-Unicode-Values-Of-A-String

Blog Archive