954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C# function to check if a string contain chinese charater

Hi guys,

is there any build-in function in C# that can detect if a string contain Chinese/Japanese character? This string may contain alphabet, numeric, chinese and japanese characters. Appreciate any advice please. Thanks in advance!

Cheers,
Mark

markthien
Newbie Poster
19 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 
markthien
Newbie Poster
19 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Hi guys,

Sorry i am really i dumbass. below are the solution:

string word = textBox1.Text.Trim();
            bool containUnicode = false;
            for (int x = 0; x < word.Length; x++)
            {
                if (char.GetUnicodeCategory(word[x]) == UnicodeCategory.OtherLetter)
                {
                    containUnicode = true;
                    break;
                }
            }
            if (containUnicode)
            {
                MessageBox.Show("contain unicode");
            }
            else
            {
                MessageBox.Show("does not contain unicode");
            }


Enjoy!

Cheers,
Mark Thien

markthien
Newbie Poster
19 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Thank you very much. You save my day.

toyumail
Newbie Poster
1 post since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You