All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Sql,server数据库人员:常见错误_[SQL,Server教程]
asp.net2.0访问母版页的控件和属性
ASP.NET技巧:创建不了XMLHTTP控件_.net资料_编程技术
ASP.NET实现简单的验证码_[Asp.Net教程]
如何在十天内学会php之第八天_[PHP教程]
.Net开发常用十大辅助软件_[Asp.Net教程]
为AJAX应用程序构建一个错误提交系统_.net资料_编程技术
.NET
网页申请表单用户体验设计简述_[Html教程]_0
SQL循序渐进(9)SELECT语句_[SQL,Server教程]
Reading number is top 10 pictures
The woman fight much more than men
30 beautiful school beauty5
西游四格漫画(三)
So beauty, will let you spray blood6
So beauty, will let you spray blood1
美女和狗狗2
From China fortress sora aoi3
5 meters long centenarians python and melee was successfully capture king snake (figure)
Summer is most suitable for young people to travel in China4
移民小国也实惠2
Download software ranking
Boxer vs Yellow4
Red cliff
塘西风月痕
Adobe Flash Player(IE) 10.0.32.18 浏览器专用的FLASH插件
Rio big adventure
Boxer's Top ten classic battle8
WebService在.NET中的实战应用教学视频 → 第5集
天龙八部十二宫服务端
Eclipse 4.2.2 For Win32
Unix video tutorial13
delv published in(发表于) 2014/1/6 9:14:18 Edit(编辑)
用C#截取指定长度的中英文混合字符串_[Asp.Net教程]

用C#截取指定长度的中英文混合字符串_[Asp.Net教程]

用C#截取指定长度的中英文混合字符串_[Asp.Net教程]

我们常做的一件事情,就是在文章系统中,截取一定长度的文章标题,超过指定长度,就加“...”


如两个字符串:
string str1 = "中国人要啊abc呀~";
string str2 = "1中国人23456abc呀~";


要截取后,输出:


str1 = "中国人要...";
str2 = "1中国人2...";


即要把中英文混合的字符串,在截取后,长度要一致,即8个字节的长度(不包括三个点),而且不能出现中文被从中间截断的情况。于是写了个方法:


public static string getStr(string s,int l)
{
string temp = s ;
if (Regex.Replace(temp,"[\u4e00-\u9fa5]","zz",RegexOptions.IgnoreCase).Length<=l)
{
return temp;
}
for (int i=temp.Length;i>=0;i--)
{
temp = temp.Substring(0,i);
if (Regex.Replace(temp,"[\u4e00-\u9fa5]","zz",RegexOptions.IgnoreCase).Length<=l-3)
{
return temp + "";
}
}
return "";
}
调用:
string content = "中国人啊abc呀呀呀呀";
content = getStr(content,13);


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.