首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

汉语言 字符串 截取

2012-06-27 
中文 字符串 截取用到中文截取,老是乱码:根据网上找到的信息,拼凑出如下一段代码:?/** 字符串截取 *///str

中文 字符串 截取

用到中文截取,老是乱码:

根据网上找到的信息,拼凑出如下一段代码:

?

/** 字符串截取 */
//str(要截取的字符串)/len(保留长度)/elide(用什么字符串结尾,类似...效果)
public static String splitString(String str, int len, String elide) {if (str == null) {return "";}int k = 0;String new_str = "";for (int i = 0; i < str.length(); i++) {byte[] b = (str.charAt(i) + "").getBytes();k = k + b.length;if (k > len) {break;}new_str = new_str + str.charAt(i);}return new_str + elide.trim();}
?

?


不好意思!忘加上了!

热点排行