王丹凤近况,9c8881,黑龙公主套
/// <summary> /// 按不同的字节编码,通过字节数去截取字符串 /// 数据库utf-8 1个数字、字母、英文符号算1个长度 1个中文、中文符号算3个长度 /// </summary> /// <param name="origstr">需截取的字符串</param> /// <param name="byteslength">需截取的字节长度</param> /// <param name="dstencoding">截取的字节编码类型</param> /// <returns></returns> public static string getsubstring(string origstr, int byteslength, encoding dstencoding) { if (origstr == null || origstr.length == 0 || byteslength < 0) return ""; int bytescount = dstencoding.getbytecount(origstr); if (bytescount > byteslength) { int readylength = 0; int bytelength; for (int i = 0; i < origstr.length; i++) { bytelength = dstencoding.getbytecount(new char[] { origstr[i] }); readylength += bytelength; if (readylength == byteslength) { origstr = origstr.substring(0, i + 1);// + "..."; 加省略号 break; } else if (readylength > byteslength) { origstr = origstr.substring(0, i);// + "..."; 加省略号 break; } } } return origstr; }
sting newstr = getsubstring(origstr, byteslength, encoding.utf8);
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论