Method 1: Use the c # program for processing.
Code attachment
View Code
/// <Summary> /// return the mixed length of a string /// </summary> /// <param name = "sourceStr"> source string </param>/ // <returns> </returns> public static int MixLength (this string sourceStr) {int mixLength = sourceStr. length; for (int I = 0; I <sourceStr. length; I ++) {byte [] bytes = Encoding. default. getBytes (sourceStr. substring (I, 1); if (bytes. length> 1) {mixLength ++;} return mixLength ;} /// <summary> // intercept a mix of Chinese and English strings equivalent to mixLength. // </summary> /// <param name = "sourceStr"> source string </param> // <param name = "mixLength"> specifies the length to be truncated, calculate the length unit of two Chinese characters </param> // <returns> </returns> public static string MixSubstring (this string sourceStr, int mixLength) {int length = mixLength; bool flag = false; // indicates whether the length is reduced by 1 int I = 0; while (I <length) {if (flag) {length --; flag = false; // reset} byte [] bytes = Encoding. default. getBytes (sourceStr. substring (I, 1); if (bytes. length> 1) // if it is Chinese, the next time you subtract one {flag = true;} I ++;} return sourceStr. substring (0, length );}
Disadvantage: Chinese characters are not twice the length of English characters on the displayed interface.
Method 2: Use css to control the style.
If the content of td in the control table is omitted, add the style table-layout: fixed to the table first;
Then add the style to the corresponding td:
. Ellipsis {width: 200px; // The white-space: nowrap; word-break: keep-all; overflow: hidden; text-overflow: ellipsis ;}
If it is a span or div, apply the style directly.
Disadvantage: there is a slight difference between different browsers, but it is very accurate compared to the first method.