文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Windows Live Writer And Code High Light Test

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;
        }
}
相关阅读 更多 +
排行榜 更多 +
翌日波奇狗的历险记手机版下载

翌日波奇狗的历险记手机版下载

休闲益智 下载
怪兽远征安卓版下载

怪兽远征安卓版下载

角色扮演 下载
谷歌卫星地图免费版下载

谷歌卫星地图免费版下载

生活实用 下载