• Post Reply Bookmark Topic Watch Topic
  • New Topic

problems with UTF8 character when saving into third-part system (ASCII)  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi,

i have come across this problem where one of our bespoke applications only supports ASCII but our integration systems use Java.
so when we have strings that contains characters outside the ASCII spectrum, our bespoke application call fails.
it seems that we have to convert these strings into ASCII before calling this application.

so my question is to find out the best way to handle this in Java.

for instance, we have a string like:

Nicolas Systèmes

how can i convert it to ASCII in such a way that you can still recognise it?
as something like this:

Nicolas Systemes

thanks,
 
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't directly since there are only 127 ASCII characters and 65536 single character code points. I have done this before using escape sequences to represent everything outside of 0x20 to 0x7e and when the target string contains just a few non ASCII characters it is still readable but it soon becomes unreadable. As an implementation of this a simple approach would be to use getBytes("utf-8") and then convert to \uxxxx encoding for all bytes outside of the ASCII set. If you use this beware of the character sequence "\u" in the un-encoded string; these will need to be handled as specials.

 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search for "java remove diacritical marks". There are ways to do this, but there will be limitations - not everything can be cleanly or easily converted into ASCII. (And once you've converted it to ASCII, you've lost information, so it's not possible to convert it back).
 
nicolas diogo
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the pointers

i will follow them up

with regards,
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!