Hmm....
I thought I'd see if the C-style escape sequences were available
(deliberately not looking in the spec) so I tried:
string s1 = "\0x40"; // in C you'd expect this to be U+0040 = "@"
string s2 = "\040"; // In C you'd expect this to be U+0020 = " "
This compiled correctly, but when run, both strings were reported to be of
length 0! How can you explain this? Is the first '\0' interepreted as EOS? I
didn't think strings were EOS-terminated in .NET (of course on the most part
there's no need to know about the internal representation of string but I
thought they used the COM BSTR encoding.)
Trying this:
char c1 = '\0x40';
char c2 = '\040';
In both cases this produced the error 'CS1012: Too many characters in string
literal'. So I inferred that in the 'string' example the "[x]40" after the
"\0" are being interpreted as separate characters, and the "\0" indicates
EOS.
Sure enough, the lines:
string s1 = "\0x40";
System.Console.WriteLine("{0}", s1.Substring(1));
write out "0x40".
Is this a bug in String.Length?
S.
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
br <se******@aol.com> wrote: I need to define a constant for a character in my
Constant class.
I defined as follows
public const char = '\136';
when I compile I get the error 'Unrecognized escape
sequence'
How do I define a char constant with octal or hexadecimal
values?
I don't know about octal (I don't think it's supported), but for hex
you use either
\uxxxx or \Uxxxxxxxx
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too