• Post Reply Bookmark Topic Watch Topic
  • New Topic

String COnversion from ansi to ascii  RSS feed

 
Anand Sidharth
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a string which has French characters ("b�b�") and is in ANSI format.
I have been trying to convert this string to one of ASCII characters.
. I am able to convert ANSI characters in the range of 0-127 with this piece of code.
String a = "b�b�";
byte[] b = a.getBytes("US-ASCII");
String c = new String(b); //c holds the converted string
Since the char � has an ANSI value of 233 the conversion is causing a problem. Please let me know a way to do the conversion for strings with chars whose ANSI value is greater than 127.
Anand
 
Jacky Chow
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Anand,
You may use the constructor String(byte[] chars, String charsetName) to convert the byte array to java string!
In your example, you changes the ANSI characters to ASCII characters first, since the character "�" does not appear in ASCII, the character "�" may lost, so you can not convert ASCII characters to ANSI characters to get the character "�" back!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!