要求显示的长度有一定限制,但是显示的当中有图片连接,有小表情图表,图片连接的长度要按图片本身的长度算,不知道如何判断了,求助各位了.

解决方案 »

  1.   

    就是怎么把<img和/>之间的内容剔除,然后判断剩余的字符串的长度,
      

  2.   

    public static String splitString(String str, int len, String elide) {
    if (str == null) {
    return "";
    }
    byte[] strByte = str.getBytes();
    int strLen = strByte.length;
    int elideLen = (elide.trim().length() == 0) ? 0
    : elide.getBytes().length;
    if (len >= strLen || len < 1) {
    return str;
    }
    if (len - elideLen > 0) {
    len = len - elideLen;
    }
    int count = 0;
    for (int i = 0; i < len; i++) {
    int value = (int) strByte[i];
    if (value < 0) {
    count++;
    }
    }
    if (count % 2 != 0) {
    len = (len == 1) ? len + 1 : len - 1;
    }
    return new String(strByte, 0, len) + elide.trim();
    }
    自己改改吧
      

  3.   

    splitString("你是谁他是谁", 3, "...") = 你是谁...
      

  4.   

    =.=我不知道怎么把数据库中取出的数据长度限制在一定范围内,因为数据中有图片连接,还有字体颜色之类的HTML语言,怎么判断长度啊,图片按照真实图片长度,高不能超过30象素,HTML语言不算长度.超过一定长度的显示最前面的几个字符(不算图片连接和HTNL语言)+上...