标签:字符串 截取 cut 添加 returns 长度 name bsp +=
///<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;
}
标签:字符串 截取 cut 添加 returns 长度 name bsp +=
原文地址:https://www.cnblogs.com/oralig/p/9848667.html