/// <summary> /// 按指定长度切割字符串(汉字算2个字符长度) /// </summary> /// <param name="input">输入字符串</param> /// <param name="newlinLength">按指定长度切割换行</param> /// <returns>输出字符串(中英混合行可能是newlinLength+1个长度 )</returns> public string StringSplit(string input, int newlinLength = 5) { System.Text.StringBuilder sbResult = new System.Text.StringBuilder(); int linLength = 0; for (int i = 0; i < input.Length; i++) { linLength += System.Text.Encoding.Default.GetBytes(input[i].ToString()).Length; sbResult.Append(input[i]); if (linLength > newlinLength) { linLength = 0; sbResult.Append(Environment.NewLine); } } return sbResult.ToString(); } /// <summary> /// 按指定长度切割字符串(汉字算1个字符长度) /// </summary> /// <param name="input">输入字符串</param> /// <param name="newlinLength">按指定长度切割换行</param> /// <returns>输出字符串数组</returns> public string[] StringSplit2(string input, int newlinLength = 5) { //string reg = @"(?<=G.{5})(?!$)"; //string reg2 = "(?<=\G.{5})"; var temp = Regex.Split(input, @"(?<=G.{" + newlinLength + "})(?!$)"); //temp.ToList().ForEach(t => Console.WriteLine(t)); return temp.ToArray<string>(); }