限制字符串大小 要求显示的长度有一定限制,但是显示的当中有图片连接,有小表情图表,图片连接的长度要按图片本身的长度算,不知道如何判断了,求助各位了. 解决方案 » 免费领取超大流量手机卡,每月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语言)+上... 为什么ch[i]改为ch之后就提示>=不能用于比较char,char[] 类型呢? 编程题 灵异事件啊,日期转换出了问题,那位帮我看看这诡异的代码吧 怎样在c代码当中用JNI来获取java程序的exit code 编的程序在Applet显示不出图片? 求解进程问题 java怎么编程其他平台软件呢,比如控制某个硬件设备,是用的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();
}
自己改改吧