从Java中删除字符串中的特定字符

Sup*_*Man 11 java

例如,给定一个字符串,Battle of the Vowels:Hawaii vs Gronzy当我们指定要删除的字符时aeiou,该函数应该将字符串转换为Bttl f th V wls:Hw vs Grzny.

在Programming Interviews Exposed一书中找到了这个问题.这在C中有解释,但我对Java很感兴趣.

Mik*_*ffe 22

一种简单的方法是使用正则表达式:

"Battle of the Vowels:Hawaii vs Gronzy".replaceAll("[aeiou]","")
Run Code Online (Sandbox Code Playgroud)

一些Java类库API文档:

String.replaceAll:http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#replaceAll( java.lang.String,%20java.lang.String )

模式和正则表达式:http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html#sum