Re: Unicode escapes and String literals?
On 13/12/2012 3:58 PM, markspace wrote:
On 12/13/2012 10:47 AM, Knute Johnson wrote:
I want to be able to do it to a String not to a string literal.
Daniel showed one way to interpret your request. Here's another. Pay
special attention to the bits out side the quotes. This program prints
"fed".
public class EscapeTest {
public static void main(String[] args) {
String \u0066\u0065\u0064 = "\u0066\u0065\u0064";
System.out.println( fed );
}
}
Cute. But presupposing that the OP isn't the idiot some people seem to
have assumed, I suspect he meant something more like
String line = someBufferedFile.readline();
... change all \u escapes into unicode in "line" ... [1]
where by "\u escapes" he mean the 6-character substrings one usually
types in string literals. The OP needs to look into "code points" and
the corresponding codepoint to Character conversions at
http://docs.oracle.com/javase/7/docs/api/java/lang/Character.html
[1] which, for the pedantic, really means "create a new string(buffer)
from line"