View Single Post
Old 06-03-2004, 07:15 AM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
Do you mean a String as in the whole unicode set (Java doesn't use ASCII), or a String as in "14"?

What I would do is grab the char array (char can be cast as int), then call Integer.toHexString() on each of the characters, shoving them into a StringBuffer.

So:

Code:
char[] chars = foo.toCharArray();
StringBuffer output = new StringBuffer();
for(int i = 0; i < chars.length; i++){
  output.append(Integer.toHexString((int)chars[i]));
}
__________________
GitS
Belisarius is offline   Reply With Quote