java中按字节截取String字符串.
类别: JAVA教程
/**
* 取字符串的前toCount个字符
*
* @param str 被处理字符串
* @param toCount 截取长度
* @param more 后缀字符串
* @version 2004.11.24
* @author zhulx
* @return String
*/
public static 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 = str.valueOf(tempChar[kk]);
byte[] b = s1.getBytes();
reInt += b.length;
reStr += tempChar[kk];
}
if (toCount == reInt || (toCount == reInt - 1))
reStr += more;
return reStr;
}
* 取字符串的前toCount个字符
*
* @param str 被处理字符串
* @param toCount 截取长度
* @param more 后缀字符串
* @version 2004.11.24
* @author zhulx
* @return String
*/
public static 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 = str.valueOf(tempChar[kk]);
byte[] b = s1.getBytes();
reInt += b.length;
reStr += tempChar[kk];
}
if (toCount == reInt || (toCount == reInt - 1))
reStr += more;
return reStr;
}
- 上一篇: 一个简单的用JAVA实现的屏幕抓图(源代码)
- 下一篇: JAVA构造函数运行解析
-= 资 源 教 程 =-
文 章 搜 索