HAS的日记正在维护的站点 作者: HAS 时间: 2020-02-07 分类: 默认的分类 评论 [scode type="green"]HAS的日记 主要维护业务[/scode] [button type="round" color="danger" url="https://haser.top/ "]点击跳转[/button] [scode type="green"]HAS的日记 微信公众号平台[/scode] [button type="round" color="danger" url="https://cnd.haser.top/2019/11/14/5bf5793535615.png "]扫码关注[/button] ------------ [scode type="green"]HAS项目文档[/scode] [button type="round" color="danger" url="https://document.haser.top/ "]点击跳转[/button] ------------ [scode type="green"]HAS Api平台 可能停止维护[/scode] [button type="round" color="danger" url="https://api.haser.top/ "]点击跳转[/button] ------------ [scode type="green"]HAS的图床\网盘[/scode] [button type="round" color="danger" url="http://img.haser.top/ "]点击跳转[/button] ------------ [scode type="green"]资源整合 精简版[/scode] [button type="round" color="danger" url="https://haser.top/independent/resources/ "]点击跳转[/button] ------------ [scode type="green"]HASPassword 维护地址[/scode] [button type="round" color="danger" url="https://blog.haser.top/ "]点击跳转[/button]
C# 截取指定长度字符串 作者: HAS 时间: 2020-02-04 分类: 学习笔记 评论 ```csharp /// /// 截取指定长度字符串 /// /// 要处理的字符串 /// 指定长度 /// 返回处理后的字符串 public static string ClipString(string inputString, int len) { bool isShowFix = false; if (len % 2 == 1) { isShowFix = true; len--; } System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding(); int tempLen = 0; string tempString = ""; byte[] s = ascii.GetBytes(inputString); for (int i = 0; i < s.Length; i++) { if ((int)s[i] == 63) tempLen += 2; else tempLen += 1; try { tempString += inputString.Substring(i, 1); } catch { break; } if (tempLen > len) break; } byte[] mybyte = System.Text.Encoding.Default.GetBytes(inputString); if (isShowFix && mybyte.Length > len) tempString += "…"; return tempString; } ```