您现在的位置是:网站首页> 编程资料编程资料
ASP.NET两个截取字符串的方法分享_实用技巧_
2023-05-24
303人已围观
简介 ASP.NET两个截取字符串的方法分享_实用技巧_
两个截取字符串的实用方法(超过一定长度自动换行)
///
/// 截取字符串,不限制字符串长度
///
/// 待截取的字符串
/// 每行的长度,多于这个长度自动换行
///
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中TextBox只能输入数字的最简洁的两种方法_实用技巧_
- ASP.net中网站访问量统计方法代码_实用技巧_
- .NET下实现数字和字符相混合的验证码实例_实用技巧_
- ASP.NET实现TreeView的XML数据源绑定实例代码_实用技巧_
- ASP.NET中水晶报表的使用方法详解_实用技巧_
- ASP.NET中URL Rewrite的具体实现方法_实用技巧_
- ASP.NET学习路线图浅谈_实用技巧_
- asp.net显示图片到指定的Image控件中 具体实现_实用技巧_
- KindEditor图片上传的Asp.net代码实例_实用技巧_
