C # extract Chinese Characters

Source: Internet
Author: User

Today, my friend asked me how to extract Chinese characters from a string. Because my friend has been working for several years, I suspect that there are some advanced statements here.)

Here, we also had a big joke about this big circle.

A few days ago, on the C # subject matter, I saw that 16 bits was not enough to indicate all Unicode characters. I naturally thought of Chinese (it was a terrible short circuit ...)

So I thought it was complicated. Then, my friend gave me a dish and said a Chinese sentence. Isn't it two bytes? I suddenly woke up otz.

 

The following is the Code implemented using regular expressions. In short, it is very simple, so I doubt if I want to be simple (for example, the problem between half-width and full-width? ):

Code:
  1. Public String test (string S)
  2. {
  3. String result = NULL;
  4. For (INT I = 0; I <S. length; I ++)
  5. {
  6. RegEx RX = new RegEx ("^ [/u4e00-/u9fa5] $"); // Unicode range of Chinese Characters
  7. If (RX. ismatch (s [I]. tostring ()))
  8. {
  9. Result + = s [I]. tostring ();
  10. }
  11. }
  12. Return result;
  13. }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.