ASP.NETで文字列を切り取る方法
946 ワード
///
///
///
///
///
///
/// , , ,
public static string StringTruncat(string oldStr, int maxLength, string endWith)
{
if (string.IsNullOrEmpty(oldStr))
// throw new NullReferenceException( " ");
return oldStr + endWith;
if (maxLength < 1)
throw new Exception(" [0] ");
if (oldStr.Length > maxLength)
{
string strTmp = oldStr.Substring(0, maxLength);
if (string.IsNullOrEmpty(endWith))
return strTmp;
else
return strTmp + endWith;
}
return oldStr;
}