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.