限制字符串大小 要求显示的长度有一定限制,但是显示的当中有图片连接,有小表情图表,图片连接的长度要按图片本身的长度算,不知道如何判断了,求助各位了. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是怎么把<img和/>之间的内容剔除,然后判断剩余的字符串的长度, 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(); }自己改改吧 splitString("你是谁他是谁", 3, "...") = 你是谁... =.=我不知道怎么把数据库中取出的数据长度限制在一定范围内,因为数据中有图片连接,还有字体颜色之类的HTML语言,怎么判断长度啊,图片按照真实图片长度,高不能超过30象素,HTML语言不算长度.超过一定长度的显示最前面的几个字符(不算图片连接和HTNL语言)+上... 在main方法中开启线程与@Test中开启线程 火急,火急 请大家帮忙,一个不难的问题 如何判断随机函数? 一个很菜的问题,请教大家! 以血的教训请教 字符串处理简单问题,大家快来帮忙呀!^_^ 有哪个大哥大姐知道java中StringReader()的用法与意义。 关于文件类File()的问题 偶想学JAVA,拜托各位介绍一下新手入门的好书啊! 静态的方法与属性不可以被继承对吗? 用Middlegen只生成出.hbm.xml 文件,java 文件出不来,怎么办啊?
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();
}
自己改改吧