截取字符串(中英混合串)-JAVA代码
来源:互联网 发布:宏观经济数据 编辑:程序博客网 时间:2024/06/10 13:54
public class SplitString {
/**
* @param args
*/
public static void main(String[] args) {
String str = "中Zell中国5000年,Congruations!";
int bytes = 8;
str = new SplitString().getSubString(str, bytes);
System.out.println(str);
}
public String getSubString(String str,int bytes){
int temp = bytes;
byte [] AllBytes = str.getBytes();
int AllStrByteLen = AllBytes.length;
if(bytes > AllStrByteLen | bytes <= 0){
return str;
}
int ChinaWordsNum = 0;
for(int i=0;i<temp;i++){
int IntOfByte = (int)AllBytes[i];
if(IntOfByte < 0 ){
ChinaWordsNum+=1;
}
}
if(ChinaWordsNum%2 == 0){
return new String(AllBytes,0,temp);
}else{
if(bytes == 1){
return null;
}
}
return new String(AllBytes,0,temp-1);
}
public String getSubString(String SubjectString, int start, int length){
String ResultString = null;
try {
Pattern regex = Pattern.compile("^.{" + start + "}(.{" + length + "}).*$");
Matcher regexMatcher = regex.matcher(SubjectString);
System.out.println(regexMatcher.matches());
try {
ResultString = regexMatcher.replaceAll("$1");
} catch (IllegalArgumentException ex){
} catch (IndexOutOfBoundsException ex){
}
}catch(PatternSyntaxException ex){
}
return ResultString;
}
}
- 截取字符串(中英混合串)-JAVA代码
- PHP中英混合字符串截取的函数代码
- php中英混合字符串截取的函数代码
- Java截取中英文混合字符串
- Java 截取中英文混合字符串
- Java 截取中英文混合字符串
- 中英混合字符串按字节截取的小问题
- c# 截取 字符串 固定长度 中英混合
- PHP截取中英混合字符串(UTF-8)
- (JAVA)截取中英文混合字符串
- java按字节截取中英文混合字符串
- (JAVA)截取中英文混合字符串
- JAVA中截取字符串
- java中截取字符串
- 截取中英文混合字符串
- 截取中英文混合字符串
- 中英文混合字符串截取
- 中英文混合字符串截取
- ResourceBundle和Properties类的区别
- 在Linux下看电视
- JAVA冒泡算法和选择算法代码
- 性能优化及用户体验
- C++练笔例子3
- 截取字符串(中英混合串)-JAVA代码
- 每天都有新发现
- 堆栈入门——堆和栈区别
- 操作系统exp1
- 遭遇Asp.Net长文件名下载的问题和解决办法
- 李开复谈中美创业差异:在中国一切从人开始
- 高度100%的绝对定位自适应布局
- 2010.4.29新老系统互连等
- 已成功与服务器建立连接 但是在登录过程中发生错误。 provider 共享内存提供程序 error 0 管道的另一端上无任何进程。