Pau*_*sik 15
抛出一些奇怪处理的代码:(请注意,它会在输出循环中跳过空标记.这很快且很脏.)您可以将需要分割和删除的任何字符添加到正则表达式模式中.(tchrist是对的.\ s的内容很糟糕,只能在一些非常简单的情况下使用.)
public class SomeClass {
public static void main(String args[]) {
String input = "The\rquick!brown - fox\t\tjumped?over;the,lazy\n,,.. \nsleeping___dog.";
for (String s: input.split("[\\p{P} \\t\\n\\r]")){
if (s.equals("")) continue;
System.out.println(s);
}
}
}
INPUT:
The
quick!brown - fox jumped?over;the,lazy
,,..
sleeping___dog.
OUTPUT:
The
quick
brown
fox
jumped
over
the
lazy
sleeping
dog
Run Code Online (Sandbox Code Playgroud)