Feb 22

Unicode string can contain lots lots of characters we don’t always want to deal with.

If you know specifically what characters you want to get rid of then you can use replaceAll() to get rid of them. But for a more general solution Java provides the java.text.Normalizer class.

The Normalizer class transforms Unicode text into an equivalent composed or decomposed form. Here is an example of its usage:

// Use Canonical decomposition
String normalized = Normalizer.normalize(unicodeString, 
   Normalizer.Form.NFD);

written by objects \\ tags: , , , ,

May 05

If you have a hex value as a string and you need the ASCII character that corresponds to that value then you need to parse your string to get its value. Once you have its value it is a simple cast to convert it to an ASCII character

eg. 4A (hex) -> 74 (dec) -> ‘J’

// First parse the hext String

int value = Integer.parseInt(hexString, 16);

// Then cast it to a char

char c = (char) value;

written by objects \\ tags: , ,

Sep 23

By simply casting it to an int.


char c = 'A';
int value = (int) c; 

written by objects \\ tags: , ,