0

I'm pro-grammatically reading emails from Exchange 2010 that have been sent in plain text. In my parsing tests to ensure the email is valid I do a series of validations, one being checking the beginning text (StartsWith precisely). When I manually copy and paste the email from Exchange into Visual Studio 2008 the start of the email looks like \r\n \x0002\r\n. I believe \x0002 is a smiley face (STX) judging from my research. However, programatically retrieving the email from Exchange as well as viewing it in Outlook the \x0002 character displays as a . Ideally, I would like to parse what's retrieved from Exchange (\r\n ㅁ\r\n) and convert it to \r\n \x0002\r\n.

For what it's worth, ReSharper is the one who converted the original string to include \x0002.

Is this possible?

gcso
  • 2,315
  • 3
  • 28
  • 50

1 Answers1

2

It sounds like you want one of the following:

Encoding.Unicode.GetBytes(myString);
Encoding.Unicode.GetChars(myString);

To format a char or a byte as a unicode character (e.g. "\uFF66" or "\x0002") see the following question:

Converting Unicode strings to escaped ascii string

Community
  • 1
  • 1
Justin
  • 84,773
  • 49
  • 224
  • 367
  • Thanks for the answer. I was *almost* at that point of my attempts. How do you get it to return `\x0002` as opposed to the smiley face? – gcso Apr 14 '11 at 01:43
  • @gcso That was actually trickier than I though it would be - I've updated my answer. For your purposes I think you are better comparing against a character, rather than converting a character to its escaped string representation. – Justin Apr 14 '11 at 01:56