当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > ASP.NET 字符串截取

ASP.NET
asp.net DataFormatString格式化GridView
ASP.NET生成Google网站地图的代码
ASP.NET(C#)中遍历所有控件
ASP.NET 程序优化 小结
asp.net 自制的单选、多选列表实现代码
ASP.NET 前台javascript与后台代码调用
ASP.NET FileUpload 上传图片实例
TextBox的宽度随输入的文本的大小而改变的js代码
VisualStudio 2008中常用快捷键
ASP.NET开发者使用jQuery应该了解的几件事情
xml 文件的创建和读取代码
ASP.NET 页面之间传递参数方法汇总
ASP.NET效率陷阱之——Attributes
C#.NET中关于结构与类之间的区别
ASP.NET 2.0中发送电子邮件剖析之一
ASP.NET四种页面导航方式之比较与选择
错误处理
ASP.NET底层架构探索之再谈.NET运行时(一)
认识Web.config文件
解读C#中的正则表达式

ASP.NET 字符串截取


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 52 ::
收藏到网摘: n/a

两个截取字符串的实用方法(超过一定长度自动换行)
复制代码 代码如下:

**////
/// 截取字符串,不限制字符串长度
///
/// 待截取的字符串
/// 每行的长度,多于这个长度自动换行
///
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;
}