2008-05-10
JAVA字节截取
/**
* 按字节长度截取字符串
*
* @param str
* 将要截取的字符串参数
* @param toCount
* 截取的字节长度
* @param more
* 字符串末尾补上的字符串
* @return 返回截取后的字符串
*/
public String substring(String str, int toCount, String more) {
int reInt = 0;
String reStr = "";
if (str == null)
return "";
char[] tempChar = str.toCharArray();
for (int kk = 0; (kk < tempChar.length && toCount > reInt); kk++) {
String s1 = String.valueOf(tempChar[kk]);
byte[] b = s1.getBytes();
reInt += b.length;
reStr += tempChar[kk];
}
if (toCount == reInt || (toCount == reInt - 1))
reStr += more;
return reStr;
}
发表评论
- 浏览: 52378 次
- 性别:

- 来自: 远方的山边

- 详细资料
搜索本博客
我的相册
denglu
共 25 张
共 25 张
最新评论
-
gentoo autounmask
http://www.91linux.com/html/linux_pub/ge ...
-- by BIGN -
一些grub引导
default 0 timeout 10 title=Gentoo r ...
-- by BIGN -
一些grub引导
http://linux.chinaunix.net/bbs/archiver/ ...
-- by BIGN -
在ubuntu下安装java
/etc/profile.d创建java.sh文件 内容: JAVA_H ...
-- by BIGN -
在ubuntu下安装java
/etc/profile.d创建java.sh文件 内容: JAVA_H ...
-- by BIGN






评论排行榜