{
ReCutstr = string1;
}
return ReCutstr;
}
//·½·¨¶þ£º
public static string CutStr(string input,int count)
{
int tempcount = count;
if (input == null)
{
return string.Empty;
}
if (input.Length > count)
{
try
{
int lencount = 0;
int.TryParse(ContainsNumeral(input,
count).ToString(), out lncount);
count = lencount + count;
if (input.Length > count)
{
return input.Substring(0, count) + "..."; }
else
{
return input;
}
}
C#截取定长字符串函数
catch
{
return input.Substring(0, tempcount) + "..."; }
}
return input;
}
/// <summary>
/// ¹ýÂ˵Ä×Ö·û´®ÖдæÔÚÊý×Öʱ£¬¡°Á½¸öÊý×ÖÔøÒ»¸ö×Ö¡±
/// </summary>
/// <param name="input"></param>
/// <param name="count"></param>
/// <returns></returns>
public static double ContainsNumeral(string input, int count) {
string linput = input.Substring(0, count);
double lcount = 0;
int i = 0;
//1.¼òµ¥ÅжÏÊý×Ö
for (int k = 0; k < 10; k++)
{
if (linput.Contains(k.ToString()))
{
lcount += 0.5;
i++;
}
}
////2.È«ÃæÅжÏÊý×Ö
//for (int j = 0; j < linput.Length; j++)
//{
// for (int k = 0; k < 10; k++)
// {
//
1).Contains(k.ToString()))
// {
// lcount += 0.5;
// i++;
// break;
// }
// }
//}
if (linput.Substring(j,
C#截取定长字符串函数
if (i % 2 != 0) {
lcount += 0.5; } return lcount; }
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说医药卫生C截取定长字符串函数(2)在线全文阅读。
相关推荐: