1

Background:

  1. I have a table in SQL database, two of the columns are English names and Simplified Chinese names.
  2. With C#, I had records of this table displayed as buttons with both names, such as: Car车. This is how I did it: button.Text = x.EnglishName + x.ChineseName; The buttons displays correctly.

3.I would like to compare button.Text to other strings, like so:

for (int K = 0; K < alist.Count; K++)
{
 string alpha = alist.[K];
 if (alpha == button.Text)
 //blahblahblah
}

Problem:

There is always an error. And I found out why: when I use Console.Writeline(button.Text), the output is Car?. Each Chinese character is turned into a "?"

So, apparently, writing Chinese characters onto the face of a button is fine. But when reading Chinese characters off the face of a button does not work.

How do I correct this?

Momom0
  • 79
  • 1
  • 9
  • 1
    What character code encoding do you have console set to by default? Character encoding can also be limited by the default console font – scrappedcola Apr 22 '16 at 18:57
  • Console.OutputEncoding = Encoding.UTF8; – Hozikimaru Apr 22 '16 at 18:58
  • _There is always an error._ What is the error? – 001 Apr 22 '16 at 19:00
  • 1
    Console.outputencoding = encoding.XXX does not work, I have tried UTF8,7,32,UNICODE all those available... – Momom0 Apr 28 '16 at 18:58
  • see this link, setting this way also works on CMD. if your cmd can show chinese, your console can show chinese. https://www.walkernews.net/2013/05/19/how-to-get-windows-command-prompt-displays-chinese-characters/ – yu yang Jian Apr 24 '18 at 01:47
  • I think this is not a duplicate of linked question as it requires some extra actions! But I have created extra answer in linked question with Chinese specific actions: https://stackoverflow.com/a/54327996/378783 – watbywbarif Jan 23 '19 at 13:12

1 Answers1

1

You might need to change the Encoding type -

Console.OutputEncoding = Encoding.Unicode  // For UTF-16

See here for other encoding types available.

Rehban Khatri
  • 924
  • 1
  • 7
  • 19