ASP.NET两个截取字符串的实用方法技巧
两个截取字符串的实用方法(超过一定长度自动换行)
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
相关阅读
- 03-14Windows2003企业版IIS6上配置asp.net4.0网站
- 03-02解决asp.net中“从客户端中检测到有潜在危险的Request.Form值”的错误
- 12-09windows server 2003配置asp.net4.0网站找不到该页等问题解决方案
- 11-13IIS 6.0优化与asp.net的web.config配置优化
- 11-11asp.net网站在 Ngnix 服务器 中配置教程
- 09-19ASP.NET设置自定义401错误页面方法详解
- 02-28asp.net“服务器应用程序不可用"解决方法
- 05-30ASP.NET AJAX配置简述
- 05-30asp.net面试试题收集
- 05-30ASP.NET MVC在IIS6下部署技巧
阅读本文后您有什么感想? 已有 人给出评价!
用户评论
热门评论
最新评论
相关软件
热点图文
- 05-02解决方法:应用程序“DEFAULT WEB SITE”中的服务器错误
- 04-04“/”应用程序中的服务器错误及解决方法
- 05-30报错“HTTP/1.1 400 Bad Request”的处理方法
- 03-09aspx文件怎么打开,ASPX的文件用什么打开?
- 04-04System.Data.SqlClient.SqlException: 无法打开登录所请求的数据库 登录失败。
- 04-17如何重新装 .Net 2.0 注册到 IIS 上面
- 11-22aspx禁止跨站、禁止读取iis信息、禁止cmd命令执行
- 06-13ASP.NET MVC中你必须知道的13个扩展点
- 10-14安装 .Net Framework4 时出错,提示“一般信任关系错误”
- 09-10利用ajax.dll进行asp.net ajax开发