asp.net截取指定长度的字符串内容

时间:2022-12-26 12:47:55
  /// <summary>
/// 用于截取指定长度的字符串内容
/// </summary>
/// <param name="sString">用于截取的字符串</param>
/// <param name="nLength">截取字符串的长度</param>
/// <returns>返回截取后的字符串</returns>
public string SubStr(string sString,int nLength)
{
if (sString.Length <= nLength)
{
return sString;
}
string sNewStr = sString.Substring(, nLength);
sNewStr = sNewStr + "...";
return sNewStr;
}