C#中英文混合字符串过长截断
/// <summary>
/// 截断字符串
/// </summary>
/// <param name="maxLength">最大长度</param>
/// <param name="str">原字符串</param>
/// <returns></returns>
public static string CutStr(int maxLength, string str)
{
string temp = str;
if (Regex.Replace(temp, "[\u4e00-\u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= maxLength)
{
return temp;
}
for (int i = temp.Length; i >= ; i--)
{
temp = temp.Substring(, i);
if (Regex.Replace(temp, "[\u4e00-\u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= maxLength - )
{
return temp + "...";
}
}
return "...";
}
C#中英文混合字符串过长截断的更多相关文章
- C#与JS实现 获取指定字节长度 中英文混合字符串 的方法
平时在作数据库插入操作时,如果用 INSERT 语句向一个varchar型字段插入内容时,有时会因为插入的内容长度超出规定的长度而报错. 尤其是插入中英文混合字符串时,SQL Server中一般中文要 ...
- PHP获取中英文混合字符串长度及截取
1.字符串长度 PHP获取中英文混合字符串长度的实现代码如下,1中文=1位,2英文=1位,可自行修改 /** * PHP获取字符串中英文混合长度 * @param $str string 字符串 * ...
- CSS截取中英文混合字符串长度
<!doctype html> <html> <head> <meta http-equiv="content-type" content ...
- 用C#截取指定长度的中英文混合字符串
很早以前写过一篇文章(用C#截取指定长度的中英文混合字符串),但是对性能没有测试,有人说我写的这个方法性能有问题,后来想,可能真会有BT之需求要求传入一个几万K甚至几M体积的字符串进来,那将会影响正则 ...
- c#的中英文混合字符串截取
public class StringHelper { public static string GetSubString(string str, int len) ...
- c#的中英文混合字符串截取 public static string SubString(string inputString, int byteLength)
/// <summary> /// c#的中英文混合字符串截取(区分中英文) /// </summary> /// <param ...
- c#的中英文混合字符串截取指定长度,startidx从0开始
//c#的中英文混合字符串截取指定长度,startidx从0开始 by gisoracle@126.com public string getStrLenB(string str, int start ...
- Lua截取utf-8编码的中英文混合字符串
参考博客:UTF8字符串在lua的截取和字数统计[转载] 需求 按字面个数来截取子字符串 函数(字符串, 开始位置, 截取长度) utf8sub(,) = 好1世界哈 utf8sub(,) = 你好1 ...
- 中英文混合字符串截取java
//截取字符串长度(中文2个字节,半个中文显示一个) public String subTextString(String str,int len){ if(str.length()<len/2 ...
随机推荐
- 怎样导入SDWebImage
Two ways : 方法1:copy all the files into your project. --下载https://github.com/rs/SDWebImage. --把SD项目co ...
- Java中堆内存(heap)和栈内存(stack)的区别
在Java代码中,常常会使用到这样的类的声明实例化: Person per = new Person(); //这其实是包含了两个步骤,声明和实例化 Person per = null; //声明一个 ...
- 个人.net学习规划路线
- hdu 1051Wooden Sticks
#include<cstdio> #include<cstring> #include<algorithm> #define maxn 10000 using na ...
- 调用API函数,在窗口非客户区绘图(通过GetWindowDC获得整个窗口的DC,就可以随意作画了)
http://hi.baidu.com/3582077/item/77d3c1ff60f9fa5ec9f33754 调用API函数,在窗口非客户区绘图 GDI+的Graphics类里有个FromHdc ...
- 创建组合索引SQL从1个多小时到1S的案例
select aa.acct_org, aa.loan_acct_no, aa.FUNCTIONARY, aa.cust_no, sum(dwm.pkg_tools.currcdtran(bb.INT ...
- POJ3026 Borg Maze(最小生成树)
题目链接. 题目大意: 任意两点(点表示字母)可以连线,求使所有点连通,且权值和最小. 分析: 第一感觉使3维的BFS.但写着写着,发现不对. 应当用最小生成树解法.把每个字母(即A,或S)看成一个结 ...
- 【转】 android 4.4 Step Counter Sensor计步器的使用
原文网址:http://blog.csdn.net/aikongmeng/article/details/40457233 版权声明:本文为博主原创文章,未经博主允许不得转载. Android 官方参 ...
- date命令使用总结【转载】
本文转载自:http://blog.sina.com.cn/s/blog_674b5aae0100o0w9.html 由于跨年.跨月.闰平年等特殊性,在日常编程过程中对日期的处理总是异常麻烦.目前,各 ...
- nexus私服安装
一.搭建nexus私服.当前服务器版本是jdk1.8 . nexus安装包下载:http://www.sonatype.org/nexus/archived 先是下载目前最新的版本 Nexus ...