字符串的判断

axie534 2010-06-23 06:47:10
String name="大家好hfkashk23243";


我需要对这个字符串判断


在这个字符串中 不能出现汉字

???????????????谢谢
...全文
45 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
heihei0923 2010-06-23
  • 打赏
  • 举报
回复
public String getEnglishChar(String str){
byte[] bytes = str.getBytes();
byte[] englishBytes = new byte[bytes.length];
int len = 0;
for(byte b :bytes){
if(b>=0)englishBytes[len++]=b;
}
return new String(englishBytes,0,len);
}
axie534 2010-06-23
  • 打赏
  • 举报
回复


谢谢
qingralf 2010-06-23
  • 打赏
  • 举报
回复

String s = "as123";
if(s.matches("[^\u4e00-\u9fa5]*")){
System.out.println("没中文");
}else{
System.out.println("有中文");
}
qingralf 2010-06-23
  • 打赏
  • 举报
回复

String s = "你好123";
if(s.matches(".*[\u4e00-\u9fa5].*")){
//包含中文
}else{
//不包含中文
}
applerockhool 2010-06-23
  • 打赏
  • 举报
回复
static boolean checkChinese(String name)
{
for (int i = 0; i < name.length(); i++)
{
String c = "" + name.charAt(i);
if (c.getBytes().length == 2)
{
return true;
}
}
return false;
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧