Possible to concatenate escape sequence to string?

L

Lcubed

I would like to allow the user to enter a numerical code, that I
change into hex and concatenate it to \x to print out that character.

Something like this
String str = "\x" + hexstr;
But if I do the above, then I get an "Unrecognized escape sequence"
error.

Anyone know how to accomplish this?
Thanks!
 
P

Peter Duniho

I would like to allow the user to enter a numerical code, that I
change into hex and concatenate it to \x to print out that character.

Something like this
String str = "\x" + hexstr;
But if I do the above, then I get an "Unrecognized escape sequence"
error.

The escape sequence is a compile-time thing.

If you want the user to enter the numeric code for a UTF-16 character and
convert that to a string in your code, just cast the integer value to
"char" and use it directly.

If you want to handle numeric codes for other encodings, you'll have to
convert the numeric code to the byte sequence it represents in that
particular encoding, and then decode those bytes (using, for example, the
Encoding class) to the equivalent string.

Pete
 
G

Gok

You are required to be a member to post replies. After logging in or becoming a member, you will be redirected back to this page.



Posted as a reply to:

Possible to concatenate escape sequence to string?

I would like to allow the user to enter a numerical code, that
change into hex and concatenate it to \x to print out that character

Something like thi
String str = "\x" + hexstr
But if I do the above, then I get an "Unrecognized escape sequence
error

Anyone know how to accomplish this
Thanks!

EggHeadCafe - Software Developer Portal of Choice
WCF Workflow Services Using External Data Exchange
http://www.eggheadcafe.com/tutorial...a-6dafb17b6d74/wcf-workflow-services-usi.aspx
 
G

Gok

You are required to be a member to post replies. After logging in or becoming a member, you will be redirected back to this page.



Posted as a reply to:

Possible to concatenate escape sequence to string?

I would like to allow the user to enter a numerical code, that
change into hex and concatenate it to \x to print out that character

Something like thi
String str = "\x" + hexstr
But if I do the above, then I get an "Unrecognized escape sequence
error

Anyone know how to accomplish this
Thanks!

EggHeadCafe - Software Developer Portal of Choice
WCF Workflow Services Using External Data Exchange
http://www.eggheadcafe.com/tutorial...a-6dafb17b6d74/wcf-workflow-services-usi.aspx
 
G

Gok

You are required to be a member to post replies. After logging in or becoming a member, you will be redirected back to this page.



Posted as a reply to:

Possible to concatenate escape sequence to string?

I would like to allow the user to enter a numerical code, that
change into hex and concatenate it to \x to print out that character

Something like thi
String str = "\x" + hexstr
But if I do the above, then I get an "Unrecognized escape sequence
error

Anyone know how to accomplish this
Thanks!

EggHeadCafe - Software Developer Portal of Choice
WCF Workflow Services Using External Data Exchange
http://www.eggheadcafe.com/tutorial...a-6dafb17b6d74/wcf-workflow-services-usi.aspx
 
A

Alan Pretre

Just do
String str = @"\x" + hexstr;

-- Alan
-- cleartopartlycloudy.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top