String interception I believe we are not strangers. But in the same string we need to intercept different data, such as when the data in text is converted into a table.
These data may include Chinese and so on.
This time if you use String. Length () You will find that the length of the string will be different as long as the number of Chinese is different.
Here is the code:
<summary>///intercept string///</summary>//<param name= "strline" > intercepted string < ;/param>//<param name= "dt" > Filled table </param>///<param name= "weight" > Intercept length </param> private void Getdatatodatatable (string strline,datatable dt,int[] weight) {DataRow Dr=dt. NewRow (); int sum=0; int count = 0; ArrayList num = new ArrayList (); char[] temp = strline. ToCharArray (); for (int i = 0; i < temp. Length; i++) {if (((int) temp[i]) >255)///greater than 255 are Chinese characters or special characters {num. ADD (i); }} for (int i = 0; i < dt. Columns.count; i++) {count = 0; for (int y = 0; y < Num. Count; y++) {if (Convert.ToInt32 (Num[y]) >=sum&&convert.toint32 (Num[y]) <=sum+weight[i]) {Count++; }} dr[i]=strline. Substring (Sum,weight[i]-count); Sum+=weight[i]-count; } }
This excludes the issue of the placeholder for Chinese characters.
When you calculate the overall length, the Chinese character is the position of two characters, but when you get the length of the string (string.length), only one character length is counted, which creates a positional bias.
In the process of interception, we first find the Chinese characters contained in the truncated string. This will be known to reduce the length of interception.
About string interception