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:
- Public String test (string S)
- {
- String result = NULL;
- For (INT I = 0; I <S. length; I ++)
- {
- RegEx RX = new RegEx ("^ [/u4e00-/u9fa5] $"); // Unicode range of Chinese Characters
- If (RX. ismatch (s [I]. tostring ()))
- {
- Result + = s [I]. tostring ();
- }
- }
- Return result;
- }