擷取字串

BIGBOY_GU發表於2018-07-06

/// <summary>
/// 擷取字串
/// </summary>
/// <param name=”text”>需要擷取的字串</param>
/// <param name=”maxLength”>長度</param>
/// <param name=”ishaspoint”>是否需要省略號</param>
/// <returns>string</returns>
public static string substr(string text, int maxLength, bool ishaspoint)
{
if (text.Length > maxLength)
{
if (ishaspoint)
return text.Substring(0, maxLength) + “…”;
else
return text.Substring(0, maxLength);
}
else return text;
}

相關文章