ASP.NET两个截取字符串的方法分享
2018-10-12 13:53
465 查看
两个截取字符串的实用方法(超过一定长度自动换行)
///
/// 截取字符串,不限制字符串长度
///
/// 待截取的字符串
/// 每行的长度,多于这个长度自动换行
///
public string CutStr(string str,int len)
{ string s="";for(int i=0;i 11 {
int r= i% len;
int last =(str.Length/len)*len;
if (i!=0 && i<=last)
{if( r==0)
{
s+=str.Substring(i-len,len)+"";
}}
else if (i>last)
{
s+=str.Substring(i-1) ;
break;
}}
return s;
}
///
/// 截取字符串并限制字符串长度,多于给定的长度+。。。
///
/// 待截取的字符串
/// 每行的长度,多于这个长度自动换行
/// 输出字符串最大的长度
///
public string CutStr(string str,int len,int max)
{
string s="";
string sheng="";
if (str.Length >max)
{
str=str.Substring(0,max) ;
sheng="";
}
for(int i=0;i 53 {
int r= i% len;
int last =(str.Length/len)*len;
if (i!=0 && i<=last)
{if( r==0)
{
s+=str.Substring(i-len,len)+"";
}}
else if (i>last)
{
s+=str.Substring(i-1) ;
break;
}}
return s+sheng;
}
您可能感兴趣的文章:
相关文章推荐
- ASP.NET两个截取字符串的方法分享
- ASP.NET两个截取字符串的方法分享
- ASP.NET技巧:两个截取字符串的实用方法
- ASP.NET两个截取字符串的实用方法技巧
- ASP.NET技巧:两个截取字符串的实用方法
- Asp.Net截取两个相同字符之间的字符串内容(示例)
- ASP.NET中过滤HTML字符串的两个方法
- asp.net 截取带有html标签的字符串(先过滤html,再截取)的方法
- asp.net 将指定字符串按指定长度进行截取并用其他字符串替换方法
- asp.net截取字符串方法
- asp.net 关于字符串内范围截取的一点方法总结
- asp.net 关于字符串内范围截取的一点方法总结
- asp.net在前台将指定字符串按指定长度进行截取并用其他字符串替换方法
- asp.net 关于字符串内范围截取的一点方法总结
- asp.net字符串分割函数使用方法分享
- ASP.NET中过滤HTML字符串的两个方法
- ASP.NET中过滤HTML字符串的两个方法
- asp.net 自定义截取字符串方法
- ASP.NET中过滤HTML字符串的两个方法
- asp.net截取字符串方法