In typographical layout, we basically think that an English character occupies 1/2 of the width of Chinese characters, and Twitter contains 140 characters. In English, there are actually few words to write, the 140 Chinese Characters in Chinese can basically express a point of view clearly. Therefore, in some cases, it is required that English characters are calculated by half of Chinese characters. Therefore, you can use regular expressions to match whether each character is a Chinese character. Matching Based on different needs
[\ U4e00-\ u9fa5] matching simplified
[\ U4e00-\ u9fff] matches simplified and traditional
[\ U2e80-\ u9fff] matches all languages in East Asia.
/// <Summary> <br/> // check the length of both Chinese and English characters (0.5 for English characters and 1 for Chinese characters) <br/> // </Summary> <br/> // <Param name = "Source"> </param> <br/> // <returns> </returns> <br/> private float getstringlengthwithchinlish (string source) <br/>{< br/> RegEx r = new RegEx (@ "[\ u4e00-\ u9fa5]"); // Chinese <br/> float Len = 0.0f; <br/> char [] stringchar = source. tochararray (); <br/> foreach (char CHR in stringchar) {<br/> console. write (CHR. tostring (); <br/> If (R. ismatch (CHR. tostring () {<br/> Len + = 1; <br/>}else {<br/> Len + = 0.5f; <br/>}</P> <p> return Len; <br/>}< br/>