ASP.NET两个截取字符串的方法分享
ASP.NET两个截取字符串的方法分享
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:两个截取字符串的实用方法(超过一定长度自动换行)//////截取字符串,不限制字符串长度//////待截取的字符串///每...

复制代码 代码如下:

两个截取字符串的实用方法(超过一定长度自动换行)

///

/// 截取字符串,不限制字符串长度

///

/// 待截取的字符串

/// 每行的长度,多于这个长度自动换行

///

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教程学习
编程开发子分类