using System;
namespace Test
{
class Program
{
static void Main()
{
string ss = "abcdefg123456789";
string str = CutString(ss);
Console.WriteLine(str);
/*
abcdefg123...
*/
Console.ReadLine();
}
/// <summary>
/// 截取字符串
/// </summary>
/// <param name="str">要截取的字符串</param>
public static string CutString(string str)
{
//字符串长度超过10,后面的显示为...
if (str.Length > 0)
{
str = str.Substring(0, 10) + "...";
}
return str;
}
public static string CutString(string str, int length)
{
if (str.Length > 0)
{
str = str.Substring(0, length) + "...";
}
return str;
}
}
}