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

ASP.NET
在ASP.NET中进行文件处理(1)
ASP.NET的实时天气及24小时天气预报
ASP.NET画图全攻略(上)
ASP.NET画图全攻略(下)
ASP.NET学习篇(1)——开篇
ASP.NET学习篇(2)——安装与配置
ASP.NET学习篇(3)——几个简单的ASP.ENT的例子
ASP.NET学习篇(4)——服务器端的控件
ASP.NET立即上手教程(1)
ASP.NET立即上手教程(2)
ASP.NET立即上手教程(3)
ASP.NET立即上手教程(4)
ASP.NET立即上手教程(5)
ASP.NET立即上手教程(6)
ASP.NET立即上手教程(8)
ASP.NET立即上手教程(7)
ASP.NET立即上手教程(9)
ASP.NET立即上手教程(10)
ASP.NET立即上手教程(11)
ASP.NET立即上手教程(12)

ASP.NET 字符串截取


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 86 ::
收藏到网摘: 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;
}