}} return System.Text.Encoding.Unicode.GetString (list. ToArray ()); varchar--20 bytes will have >=10 characters public static string cutstring (string value, int length, bool ellipsis, Cuttype cuttype) {Valu E = value. Trim (); if (value. Length = = 0) return string. Empty; if (Cuttype = = Cuttype.nvarchar) {if (value. Length > Length/2) {value = value. Substring (0, LENGTH/2); if (ellipsis) return value + "..."; }} else {string resultstring = string. Empty; byte[] MyByte = System.Text.Encoding.GetEncoding ("GBK"). GetBytes (value); if (Mybyte.length > Length) {resultstring = encoding.getencoding ("GBK"). GetString (mybyte, 0, length); String Lastchar = Resultstring.substring (resultstring.length-1, 1); if (lastchar.equals (value). Substring (resultstring.length-1, 1))) {value = resultstring;} If the last character of the intercept is equal to the character in the same position in the original input string, then the intercept completes else//if not equal, subtract one byte and then intercept {value = encoding.getencoding ("GBK"). GetString (mybyte, 0, length-1); } if (ellipsis) return value + "..."; return value; }} return value; } #region The function of the truncated string, partitioning the functions of English////////////////////////////or processed strings public static string left (string mText, int Byteco UNT) {if (ByteCount < 1) return mText; if (System.Text.Encoding.Default.GetByteCount (mText) <= byteCount) {return MText; } else {byte[] txtbytes = System.Text.Encoding.Default.GetBytes (MText); byte[] newbytes = new byte[bytecount-4]; for (i NT i = 0; i < byteCount-4; i++) {Newbytes[i] = Txtbytes[i];} string OutPut = System.Text.Encoding.Default.GetString (newbytes) + "..."; if (Output.endswith ("?...") = = True) {OutPut = output.substring (0, output.length-4); OutPut + = "...";} return OutPut; }} #endregion}/////////Intercept word Fu Yi, varchar--English one byte, Chinese two bytes, nvarchar--whether both Chinese and English are two bytes//public enum Cuttype {Varchar, NVarchar }
Length of the truncated string (Chinese and English)