循环截取字符串添加换行
///<summary>
/// 截取字符串,不限制字符串长度
///</summary>
///<param name = "str" > 待截取的字符串 </ param >
///< param name="len">每行的长度,多于这个长度自动换行</param>
///<returns></returns>
public string CutStr(string str, int len)
{
string getStr = " ";
for (int i = 0; i < str.Length; i++)
{
int r = i % len;
int last = (str.Length / len) * len;
if (i != 0 && i <= last)
{
if (r == 0)
{
getStr += str.Substring(i - len, len) + "<br>";
}
}
else if (i > last)
{
getStr += str.Substring(i - 1);
break;
}
}
return getStr;
}
反思 空杯 担当