String interception in C #

Source: Internet
Author: User
String

<summary>
function: Accurately intercept a specified length of string as required
2 English in Chinese is a
Parameters: Str to intercept character, Len intercept length symbol denotes character (...)
</summary>
public static string Gottopic (string str,int len,string symbol)
{
int count = 0;
String strtemp = "";
str = nohtml (str);
for (int i = 0; i < str. Length; i++)
{
if (Math.Abs ((int) (str. Substring (i, 1). ToCharArray ()) [0])) > 255)
{
Count + 2;
}else
{
Count + 1;
}
if (Count <= len)
{
strtemp = str. Substring (i, 1);
}
Else
{
return strtemp + symbol;
}

}
return str;
}
<summary>
Filter out HTML tags
</summary>
<param name= "str" ></param>
<returns></returns>
public static string nohtml (String str)
{
str = regex.replace (str, @ "\<.[ ^\<]*\>) "," ", Regexoptions.ignorepatternwhitespace | Regexoptions.ignorecase);
str = regex.replace (str, @ "(\<\/[^\<]*\>)", "", Regexoptions.ignorecase | Regexoptions.ignorepatternwhitespace);
return str;

}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.