IT猫扑网:您身边最放心的安全下载站! 最新更新|软件分类|软件专题|手机版|论坛转贴|软件发布

您当前所在位置:首页网络编程.Net编程 → ASP.NET两个截取字符串的实用方法技巧

ASP.NET两个截取字符串的实用方法技巧

时间:2015/6/28来源:IT猫扑网作者:网管联盟我要评论(0)

两个截取字符串的实用方法(超过一定长度自动换行)
1/**////
2 /// 截取字符串,不限制字符串长度
3 ///
4 /// 待截取的字符串
5 /// 每行的长度,多于这个长度自动换行
6 ///
7 public string CutStr(string str,int len)
8 { string s="";
9
10 for(int i=0;i 11 {
12 int r= i% len;
13 int last =(str.Length/len)*len;
14 if (i!=0 && i<=last)
15 {
16
17 if( r==0)
18 {
19 s+=str.Substring(i-len,len)+"
";
20 }
21
22 }
23 else if (i>last)
24 {
25 s+=str.Substring(i-1) ;
26 break;
27 }
28
29 }
30
31 return s;
32
33 }
34
35
36 /**////
37 /// 截取字符串并限制字符串长度,多于给定的长度+。。。
38 ///
39 /// 待截取的字符串
40 /// 每行的长度,多于这个长度自动换行
41 /// 输出字符串最大的长度
42 ///
43 public string CutStr(string str,int len,int max)
44 {
45 string s="";
46 string sheng="";
47 if (str.Length >max)
48 {
49 str=str.Substring(0,max) ;
50 sheng="";
51 }
52 for(int i=0;i 53 {
54 int r= i% len;
55 int last =(str.Length/len)*len;
56 if (i!=0 && i<=last)
57 {
58
59 if( r==0)
60 {
61 s+=str.Substring(i-len,len)+"
";
62 }
63
64 }
65 else if (i>last)
66 {
67 s+=str.Substring(i-1) ;
68 break;
69 }
70
71 }
72
73 return s+sheng;
74
75 }

关键词标签:ASP.NET

相关阅读

文章评论
发表评论

热门文章 手把手教你用好LINQ to SQL手把手教你用好LINQ to SQL在.NET环境下为网站增加IP过滤功能在.NET环境下为网站增加IP过滤功能ASP.NET 如何避免页面重新整理时重复送出ASP.NET 如何避免页面重新整理时重复送出用Asp.net扩展ExtJS用Asp.net扩展ExtJS

相关下载

人气排行 asp.net表单提交方法GET\POST在ASP.NET中如何判断用户IE浏览器的版本Asp.net中messagebox的实现方法Asp.net中的web.config配置在ASP.NET MVC中实现大文件异步上传用Iformattable接口控制.Net中文本格式c#.Net经典面试题目用Asp.net扩展ExtJS