【发布时间】:2015-05-27 10:42:32
【问题描述】:
我想要单词之间的空格。我曾尝试在 Java 中使用 Pattern.compile("a\\sb"),但 a b 失败。
这是我使用的代码:
String str;
Scanner sc=new Scanner(System.in);
System.out.println("Enter String");
str=sc.next();
Pattern pat = Pattern.compile("a\\sb");
Matcher m = pat.matcher(str);
if( m.find() ) {
System.out.println("Success");
} else {
System.out.println("Failed");
}
【问题讨论】:
-
"a\\sb"....... -
我也试过了
-
@RaghavendraDillikar 有任何错误报告吗?你使用了 Matcher 类吗?
-
这个模式看起来很不错。请给我们MVCE 解释您的问题。
-
好吧,OP提供代码后问题就很清楚了。