这篇文章介绍了C#中英文混合字符串截取函数,有需要的朋友可以参考一下
代码一
////// 截断字符串 /// /// 最大长度 /// 原字符串 ///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 >= 0; i--) { temp = temp.Substring(0, i); if (Regex.Replace(temp, "[\u4e00-\u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= maxLength - 3) { return temp + "..."; } } return "..."; }
代码二
private string GetByteString(string center, int maxlen, string endStr) { string temp = center.Substring(0, (center.Lengthmaxlen) break; } if (count <= maxlen) { outputStr = temp; endStr = ""; } outputStr += endStr; return outputStr; }
以上就是C# 截取字符串方法(包含中英混合)的实现代码,需要的朋友可以参考一下
以上就是C#中英文混合字符串截取函数的详细内容,更多请关注0133技术站其它相关文章!