John Ztwin <Jo****@mail.comwrote:
I have a file that contains ordinary text and some special charaters in
Unicode escape sequences (\uxxxx).
When I read the file using e.g. StreamReader Unicode escape sequences are
not converted to their character representation.
No, I wouldn't expect them to be. That's done by the C# compiler - it
would be a big mistake for it to be done by StreamReader.
They are shown excatly same
way than in file. Literals in C# code's variables are shown corretly.
Can anyone tell how to read Unicode escape sequences from file so that they
are presented like literals?
You basically need to parse the text you've read, just like the C#
compiler does. You can search for \u fairly easily, then take the next
four digits, complain if they're not all hex, convert the hex to a
char, then replace the whole section with the character value.
--
Jon Skeet - <sk***@pobox.com>
Web site:
http://www.pobox.com/~skeet
Blog:
http://www.msmvps.com/jon.skeet
C# in Depth:
http://csharpindepth.com