Hi Ian,
I was able to read and display test using this code:
Dim Cp950 As Encoding = System.Text.Encoding.GetEncoding(950)
Dim sr As New StreamReader("CHTText.txt", Cp950)
RichTextBox1.Text = sr.ReadToEnd()
I used the Traditional Chinese codepage, which is 950. If you're reading
Simplified Chinese, you need to use 936. Automatic encoding detection works
like this:
-If there's a byte order mark, detect the BOM and read in that encoding
-Else use the system default codepage
So for example, if you're running this code on an English OS, the encoding
would default to the Western European codepage. To override this, you need
to set the encoding to the desired encoding (like above, to cp 950). Once
the text is in memory it is stored as Unicode, so you no longer need to
convert it and it should display correctly as long as you have the correct
support on your system. I assume that you already have this support
installed since the string displayed correctly in the debugger. Hope this
helps.
Thanks,
Marin
[quoted text, click to view] "Ian Armitage" wrote:
> Hi,
>
> I am trying to display some chinese text in a RichTextBox but am having some
> problems.
>
> I open a .txt file which contains chinese text. I then convert the text
> using the appropriate codepage and the .NET Encoding class and the string in
> the debugger contains the correct chinese text. However, when I pass the
> string to the RichTextBox 'text' property the control displays entirely the
> wrong text.
>
> I have tried using 'LoadFile()' but cannot use this as I cannot be sure
> whether the file is unicode or not.
>
> Can anybody help? Is there a foolproof way of displaying chinese (or any
> other code page) text in .NET?
>
> Thanks in advance
> Ian
>
> --