#region function: getsubstring () Action: Gets a string of the specified length at the beginning of the specified position in the string, supporting Chinese characters in English mixed Chinese characters to 2 byte count//<summary>///Gets the specified position in the string starting at the specified The length of the string, supporting Chinese characters in English mixed Chinese characters is 2 byte count///</summary>//<param name= "strsub" > Input mixed Strings in English </param> <param name= "Start" > Start intercept </param>//<param name= "Length" > Length of string to intercept </param> <returns></returns> public static string getsubstring (string strsub, int start, int length) {String temp = strsub; Int j = 0, k = 0, p = 0; Charenumerator CE = temp. GetEnumerator (); while (CE. MoveNext ()) {j + = (CE. Current > 0 && CE. Current < 255)? 1:2; if (J <= start) {p++; } else {if (j = = GetLength (temp)) { temp = temp. Substring (p, k + 1); Break } if (j <= length + start) {k++; } else {temp = temp. Substring (P, k); Break }}} return temp; }///<summary>///To get the specified string length, Chinese characters are calculated in 2 bytes//</summary>//<param name= "AOr Gstr "> String to be Counted </param>//<returns></returns> private static int GetLength (String Aorgs TR) {int intlen = aorgstr.length; int i; char[] chars = Aorgstr.tochararray (); for (i = 0; i < chars. Length; i++) {if (System.Convert.ToInt32 (chars[i]) > 255) {Intlen ++; }} return Intlen; } #endregion
Gets a string of the specified length starting at the specified position in the string, supporting Chinese characters in English with a 2-byte count