1、public class DataFormat /* 按长度截取字符串,超过长度的添加省略符,显示缩写* * author YPJ* param original* param width* param ellipsis* return*/public static String abbreviate(String original, int width, String ellipsis) if (original = null | “.equals(original) return “;int byteIndex = 0;int charIndex = 0;for (; charIndex
2、256 ? byteIndex + 2: byteIndex + 1;if (byteIndex width) break;if (byteIndex width) charIndex = charIndex - ellipsis.length()/2*2;return original.substring(0, charIndex 0 ? charIndex : 0)+ ellipsis;return original.substring(0, charIndex);public static String htmlToText(String inputString) String html
3、Str = inputString;String textStr = “;String scriptRegEx = “*?sS*?“;String styleRegEx = “*?sS*?“;String htmlRegEx1 = “*“;String htmlRegEx2 = “*“;try Pattern scriptPattern = Ppile(scriptRegEx,Pattern.CASE_INSENSITIVE);Matcher scriptMatcher = scriptPattern.matcher(htmlStr);htmlStr = scriptMatcher.repla
4、ceAll(“);Pattern stylePattern = Ppile(styleRegEx,Pattern.CASE_INSENSITIVE);Matcher styleMatcher = stylePattern.matcher(htmlStr);htmlStr = styleMatcher.replaceAll(“);Pattern htmlPattern1 = Ppile(htmlRegEx1,Pattern.CASE_INSENSITIVE);Matcher htmlMatcher1 = htmlPattern1.matcher(htmlStr);htmlStr = htmlMa
5、tcher1.replaceAll(“);Pattern htmlPattern2 = Ppile(htmlRegEx2,Pattern.CASE_INSENSITIVE);Matcher htmlMatcher2 = htmlPattern2.matcher(htmlStr);htmlStr = htmlMatcher2.replaceAll(“);textStr = htmlStr; catch (Exception e) System.err.println(“-htmlToText(String inputString):“+ e.getMessage();textStr = textStr.replaceAll(“, “);textStr = textStr.replaceAll(“, “);textStr = textStr.replaceAll(“, “);textStr = textStr.replaceAll(“, “ “);textStr = textStr.replaceAll(“, “return textStr;