Windows Live Writer And Code High Light Test
时间:2011-05-13 来源:黎某人
package tools; public class StrTool { public static String substring(String string, int length) { StringBuffer sb = new StringBuffer(); if (byteLength(string) > length) { int count = 0; for (int i = 0; i < string.length(); i++) { char temp = string.charAt(i); if (Integer.toHexString(temp).length() == 4) { count += 2; } else { count++; } if (count < length) { sb.append(temp); } if (count == length) { sb.append(temp); break; } } sb.append(".."); } else { sb.append(string); } return sb.toString(); } public static int byteLength(String string) { int count = 0; for (int i = 0; i < string.length(); i++) { if (Integer.toHexString(string.charAt(i)).length() == 4) { count += 2; } else { count++; } } return count; } }
相关阅读 更多 +
排行榜 更多 +