views:

30

answers:

1
+4  Q: 

\x Escape in Java?

Hi, I was wondering if there is a similar hex (\x) escape in Java like there is in C++. For example:

char helloworld[] = "\x48\x45\x4C\x4C\x4F\x20\x57\x47\x52\x4C\x44";
printf("%s", helloworld);

There is no hex (\x) escape in Java from what it appears so far. Is there an alternative that is just as easy to use without having to concat a bunch of hex numbers together?

+4  A: 

Strings in Java are always encoded in UTF-16, so it uses a Unicode escape: \u0048. Octal characters are supported as well: \110

erickson
Thanks for the quick response. It works perfectly!.
David
@David: Don't forget to check the 'chosen answer' mark :)
helios