String
We often do one thing, is in the article system, the interception of a certain length of the article title, more than the specified length, add "..."
such as two strings:
String str1 = "Chinese people want AH abc ~";
String str2 = "1 Chinese 23456abc ~";
To intercept, after the output:
str1 = "Chinese people want ...";
str2 = "1 Chinese 2 ...";
That is, the string to be mixed in Chinese and English, after the interception, the length should be consistent, that is, 8 bytes length (excluding three points), and can not appear in the middle of the case of truncated. So I wrote a method:
public static string Getstr (String s,int L)
{
string temp = s;
if (regex.replace (temp, "[\u4e00-\u9fa5]", "ZZ", Regexoptions.ignorecase). LENGTH<=L)
{
return temp;
}
for (int i=temp. length;i>=0;i--)
{
temp = temp. Substring (0,i);
if (regex.replace (temp, "[\u4e00-\u9fa5]", "ZZ", Regexoptions.ignorecase). length<=l-3)
{
return temp + "";
}
}
Return "";
}
Call:
String content = "Chinese AH abc yes";
Content = Getstr (content,13);