How can I get this statement to work: string strData = '\xB';

  • Thread starter Thread starter Max Adams
  • Start date Start date
M

Max Adams

How can I get this statement to work:
string strData = '\xB';

I get the error: Cannot implicitly convert type 'char' to 'string'.
Can anyone help?

PT
 
Max Adams said:
How can I get this statement to work:
string strData = '\xB';

I get the error: Cannot implicitly convert type 'char' to 'string'.
Can anyone help?

Sure:

string strData = "\xB";

'' is used for specifying a single character.
"" is used for specifying a string.
 
Sure:

string strData = "\xB";

'' is used for specifying a single character.
"" is used for specifying a string.


And that will give me the code for the ASCII character <VT>??
 
Max Adams said:
And that will give me the code for the ASCII character <VT>??

Yup - although using "\v" would be simpler :)

On a related point though, when you *do* need to specify a Unicode
character in that kind of way, I'd suggest using \u instead - it's less
error prone. For instance, using your example:

"hello\xBworld" gives you what you want, but:

"hello\xBBob" doesn't, because the second B is treated as part of the
hex string too. Using

"hello\u000BBob" is fine though.
 
Back
Top