请问怎么提取字符串中的中文和数字?

sunwei_07 2007-08-13 08:23:32
比如一个字符串"sjkjlfdks你好as!kj556asd<hjkd>x"

我要提取里面的"你好"和"556"
...全文
808 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jy_game_over 2008-09-16
  • 打赏
  • 举报
回复
关注中 我也在问这个问题
顶一下 决不潜水
vitamins 2007-08-14
  • 打赏
  • 举报
回复
学习
luyang1016 2007-08-14
  • 打赏
  • 举报
回复
这个东西有什么好研究的啊,早点睡觉吧
sunwei_07 2007-08-14
  • 打赏
  • 举报
回复
是正则表达式吗?\\d+代表什么啊?数字?
leifeng20088 2007-08-14
  • 打赏
  • 举报
回复
请问
Pattern pcn=Pattern.compile("[\u4e00-\u9fa5]+");
Pattern pd = Pattern.compile("\\d+");
是什么意思啊?


同问
sunwei_07 2007-08-14
  • 打赏
  • 举报
回复
我那个字符串只是打个比方,4楼的方法是知道内容的前提了

请问
Pattern pcn=Pattern.compile("[\u4e00-\u9fa5]+");
Pattern pd = Pattern.compile("\\d+");
是什么意思啊?
("[\u4e00-\u9fa5]+");和("\\d+");
lelem 2007-08-13
  • 打赏
  • 举报
回复
String str="sjkjlfdks你好as!kj556asd<hjkd>x";//要被查找的字符串
String str1="你好";//你要提取的字符串
StringBuffer sb =new StringBuffer();

int c= str.indexOf(str1);
System.out.println(str.substring(c, str1.length()));
for(int i=0 ;i<str.length();i++){
char ch=str.charAt(i);
for(int m=0;m<10;m++){
String str1=String.valueOf(m);
if(str1.equals(String.valueOf(ch))) sb.append(ch);
}
}
System.out.println(sb);
要是字符串中有多个数字字符串像"1111你好1111"
区分开来输出的话,就在加if判断。

不知道这个对你有没有帮助!
andycpp 2007-08-13
  • 打赏
  • 举报
回复
楼上的有没有考虑增补字符集?
believefym 2007-08-13
  • 打赏
  • 举报
回复
Pattern pcn=Pattern.compile("[\u4e00-\u9fa5]+");
Pattern pd = Pattern.compile("\\d+");
String str="sjkjlfdks你好as!kj556asd<hjkd>x";
Matcher m = pcn.matcher(str);
if(m.find()){
System.out.println("中文:"+m.group());
}

m = pd.matcher(str);
if(m.find()){
System.out.println("数字:"+m.group());
}
onlytiancai 2007-08-13
  • 打赏
  • 举报
回复
用正则表达式,汉字的utf-8的码在一个范围内,什么\uxxxx

62,623

社区成员

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

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