469,604 Members | 2,318 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,604 developers. It's quick & easy.

Chinese Characters

I'm having a problem working with foreign characters (well....foreign
to me anyway)

I have a textbox control on a form. The font is set to MS Arial
Unicode. If I use the Chinese input method I can type characters
into this box no problem. They display correctly. I can also copy
and paste Chinese characters from web sites into this text box and
they display no problem.

Here is my problem. If I put some Chinese characters in the box,
then run this line of code:

txtBox.Text = txtBox.Text + " WHY ARE YOU DIFFERENT?";

The original characters change to question marks (with my new text
appended correctly after them)

So my question is - who has the problem?

First thought was the text box. But it appears to support displaying
the Chinese characters OK when I type them in. Or if I copy and paste
them from a Chinese web site using the clipboard. So it's not a font
display problem.

So that means it must be something to do with the way strings are
stored in C#? But I've heard they are all unicode. So how could
this be a problem?

The line above does not do any obvious conversion. I should get the
exact same contents of the text box (with some extra text added to the
end)

Any help would be appreciated.
Jan 8 '08 #1
5 7940
I have a textbox control on a form. The font is set to MS Arial
Unicode. If I use the Chinese input method I can type characters
into this box no problem. They display correctly. I can also copy
and paste Chinese characters from web sites into this text box and
they display no problem.
....
Any help would be appreciated.
I have tried to reproduce the problem, it all works well.
Used C#, VS 2005 (no SP1), Win XP SP2.
Created a new C# application, added a TextBox, set the font to MS Arial
Unicode, added a button and in the button event run your code.
Works ok.

Question marks mean data corruption (not bad font, or anything like this).

So, we need more data:
- Is that text box a standard or a custom text box?
- What OS version?
- What .NET version
- What language
- If you add a label and do lbl.Text = txtBox.Text (before your code),
is that ok?
- does someone overrides the get/set of Text for the textbox?
- do you have the same problem with a small, dummy application like
the one I have created/described?
- anything else that you can think of

--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Jan 8 '08 #2
Try setting the content of the textbox to unicode using classes under
System.Encoding (could be System.Text.Encoding)

Specifically this one - txtBox.Text = txtBox.Text + " WHY ARE YOU
DIFFERENT?";

HTH
Kalpesh
Jan 8 '08 #3
Try setting the content of the textbox to unicode using classes under
System.Encoding (could be System.Text.Encoding)

Specifically this one - txtBox.Text = txtBox.Text + " WHY ARE YOU
DIFFERENT?";

HTH
Kalpesh
Jan 8 '08 #4
- do you have the same problem with a small, dummy application like
* the one I have created/described?
Man, I don't know when I'm gonna learn to always just try this
first. Sure enough - a small test program did not have the
problem. So I did some digging to find what the difference was and
traced it down to a 3rd party component I had added a few months ago
to this form. It does real time spell checking as you type in a text
box and underlines mis-spelled words in red. I had forgotten all
about it.

Commenting out this component fixed my problem.

Sorry to have bothered you all with this one......[as he slinks
backward out the door with a red face and hat in hand]
Jan 8 '08 #5
Sorry to have bothered you all with this one......[as he slinks
backward out the door with a red face and hat in hand]
Don't worry, s**t happens :-)
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Jan 9 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jeff | last post: by
8 posts views Thread by Agnes | last post: by
8 posts views Thread by pabv | last post: by
reply views Thread by st.frey | last post: by
2 posts views Thread by Wassy | last post: by
5 posts views Thread by DaveRook | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.