Received: by 10.224.72.199 with SMTP id n7mr1301159qaj.5.1355427664085; Thu, 13 Dec 2012 11:41:04 -0800 (PST) Received: by 10.49.94.143 with SMTP id dc15mr622269qeb.32.1355427664064; Thu, 13 Dec 2012 11:41:04 -0800 (PST) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!fc2no597368qab.0!news-out.google.com!gf5ni48615204qab.0!nntp.google.com!fc2no597360qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Thu, 13 Dec 2012 11:41:03 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T NNTP-Posting-Host: 69.28.149.29 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <8d054b85-a6ed-4bab-a8a9-81e967a84fda@googlegroups.com> Subject: Re: Unicode escapes and String literals? From: Lew Injection-Date: Thu, 13 Dec 2012 19:41:04 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.java.programmer:20297 Knute Johnson wrote: > Thomas Richter wrote: >> Knute Johnson wrote: >>> 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 [sic] escape sequences to a String that are done by >>> string literals? They aren't done by String literals. >>> String s = "\u0066\u0065\u0064"; >>> becomes "fed" but if you create a String with \u0066\u0065\u0064 in it Exactly how? >>> without using the literal it stays \u0066\u0065\u0064. Is there a built >>> in mechanism in Java for doing that translation to a String? No. >> Yes. It's called "compiler". The same part of the compiler that That's not exactly correct, and it certainly is not the same part that translates '\t'. >> translates a "\t" in a string literal to the TAB control character also >> replaces the unicode sequences in the string literal to the >> corresponding unicode encoding. Nope. > I want to be able to do it to a String not to a string literal. You want to do what, exactly? I'm not clear on what you're trying to accomplish. '\u' sequences are pre-compile, not during compile. Their presence is exactly equivalent to typing the corresponding Unicode character directly. You can embed them in identifiers, directives, anywhere the corresponding character can go. Not just literals. For that matter, you can use them in numeric literals. package temp; /** * ShowUnicodeEscapes. */ public class ShowUnicodeEscapes { static final \u0069nt COUN\u0054 = \u0030\u003b /** * main. * * @param args String array of arguments. */ public static void main(String[] args) { System.out.println("COUNT = \u0022+ COUNT); } }