ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` //截取特定长度字符串,不够用...代替 public static string getStr2(string s, int l, string endStr) { string temp = s.Substring(0, (s.Length < l + 1) ? s.Length : l + 1); byte[] encodedBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(temp); string outputStr = ""; int count = 0; for (int i = 0; i < temp.Length; i++) { if ((int)encodedBytes[i] == 63) count += 2; else count += 1; if (count <= l - endStr.Length) outputStr += temp.Substring(i, 1); else if (count > l) break; } if (count <= l) { outputStr = temp; endStr = ""; } outputStr += endStr; return outputStr; } ```