/// <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#中英文混合字符串过长截断的更多相关文章

  1. C#与JS实现 获取指定字节长度 中英文混合字符串 的方法

    平时在作数据库插入操作时,如果用 INSERT 语句向一个varchar型字段插入内容时,有时会因为插入的内容长度超出规定的长度而报错. 尤其是插入中英文混合字符串时,SQL Server中一般中文要 ...

  2. PHP获取中英文混合字符串长度及截取

    1.字符串长度 PHP获取中英文混合字符串长度的实现代码如下,1中文=1位,2英文=1位,可自行修改 /** * PHP获取字符串中英文混合长度 * @param $str string 字符串 *  ...

  3. CSS截取中英文混合字符串长度

    <!doctype html> <html> <head> <meta http-equiv="content-type" content ...

  4. 用C#截取指定长度的中英文混合字符串

    很早以前写过一篇文章(用C#截取指定长度的中英文混合字符串),但是对性能没有测试,有人说我写的这个方法性能有问题,后来想,可能真会有BT之需求要求传入一个几万K甚至几M体积的字符串进来,那将会影响正则 ...

  5. c#的中英文混合字符串截取

    public class StringHelper     {         public static string GetSubString(string str, int len)       ...

  6. c#的中英文混合字符串截取 public static string SubString(string inputString, int byteLength)

    /// <summary>        /// c#的中英文混合字符串截取(区分中英文)        /// </summary>        /// <param ...

  7. c#的中英文混合字符串截取指定长度,startidx从0开始

    //c#的中英文混合字符串截取指定长度,startidx从0开始 by gisoracle@126.com public string getStrLenB(string str, int start ...

  8. Lua截取utf-8编码的中英文混合字符串

    参考博客:UTF8字符串在lua的截取和字数统计[转载] 需求 按字面个数来截取子字符串 函数(字符串, 开始位置, 截取长度) utf8sub(,) = 好1世界哈 utf8sub(,) = 你好1 ...

  9. 中英文混合字符串截取java

    //截取字符串长度(中文2个字节,半个中文显示一个) public String subTextString(String str,int len){ if(str.length()<len/2 ...

随机推荐

  1. ctags使用详解(转载)

    一.        ctags是干什么的 ctags的功能:扫描指定的源文件,找出其中所包含的语法元素,并将找到的相关内容记录下来. 我用的是Exuberant Ctags,在Windows上使用,就 ...

  2. codevs 1217 借教室

    传送门 1217 借教室 2012年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Descripti ...

  3. 在同个工程中使用 Swift 和 Objective-C(Swift 2.0更新)-b

    本节包含内容: Mix and Match 概述(Mix and Match Overview) 在同个应用的 target 中导入(Importing Code from Within the Sa ...

  4. RESTful API -备

    网络应用程序,分为前端和后端两个部分.当前的发展趋势,就是前端设备层出不穷(手机.平板.桌面电脑.其他专用设备......). 因此,必须有一种统一的机制,方便不同的前端设备与后端进行通信.这导致AP ...

  5. Java获取ip地址的几种方法

    以下内容介绍下java获取ip地址的几种思路. 1.直接利用java.net.InetAddress类获取,不过这种方法只在windows环境下有效,在linux环境下只能获取localhost地址( ...

  6. USB方向

    Because the host is always the bus master, it is easy to remember USB direction: OUT means from the ...

  7. 如何打开mo文件并修改 PoEdit

    mo文件是被编译了的文件,一般在汉化的时候会用到. 比如我想修改phpmyadmin 的界面信息,就需要修改phpmyadmin.mo的文件内容. 可是用编辑器editplus或者Sublime 2打 ...

  8. linux下svn修改用户名和密码

    1.临时更换,在命令下强制加上 --username 和--password选项, 例如:svn up --username zhangsan --password 123456 svn co URL ...

  9. mklink命令转移win7系统盘文件夹users和programdata(附xp的方法)

    mklink命令转移win7系统盘文件夹users和programdata(附xp的方法)                   使用mklink命令转移文件夹清理臃肿的c盘        (一) 我的 ...

  10. Word Ladder——LeetCode

    Given two words (start and end), and a dictionary, find the length of shortest transformation sequen ...