Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Roedy Green Newsgroups: comp.lang.java.programmer Subject: Re: Unicode escapes and String literals? Date: Fri, 14 Dec 2012 02:28:06 -0800 Organization: Canadian Mind Products Lines: 29 Message-ID: <3mvlc8tm36j2nrnunpl6dc3rr37jvf0p6t@4ax.com> References: Reply-To: Roedy Green NNTP-Posting-Host: K2Qzzs3EAqXk5RLzfhxcSw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Forte Agent 6.00/32.1186 Xref: csiph.com comp.lang.java.programmer:20321 On Thu, 13 Dec 2012 09:31:18 -0800, Knute Johnson wrote, quoted or indirectly quoted someone who said : >I just had a great revelation as I was putting together my SSCCE for the >question I was going to ask. So it has changed my question. How do I >do the conversion of unicode escape sequences to a String that are done >by string literals? > >String s = "\u0066\u0065\u0064"; > >becomes "fed" but if you create a String with \u0066\u0065\u0064 in it >without using the literal it stays \u0066\u0065\u0064. Is there a built >in mechanism in Java for doing that translation to a String? have a look at native2ascii IIRC it uses sequences like that in its ASCII representation which you can then convert to any encoding you like. see http://mindprod.com/jgloss/encoding.html#NATIVE2ASCII A little finite state machine should handle that fairly easily. If you find that difficult, I would write one for you. -- Roedy Green Canadian Mind Products http://mindprod.com Students who hire or con others to do their homework are as foolish as couch potatoes who hire others to go to the gym for them.