Remove specific characters from string in Java

前端 未结 3 1167
孤城傲影
孤城傲影 2021-02-20 00:28

For example, given a string of Battle of the Vowels:Hawaii vs Gronzy when we specify the characters to be removed as aeiou, the function should transfo

3条回答
  •  礼貌的吻别
    2021-02-20 00:57

    One simple way to do this is to use a regular expression:

    "Battle of the Vowels:Hawaii vs Gronzy".replaceAll("[aeiou]","")
    

    Some Java Class Library API documentation:

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

    Patterns and regular expressions: http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html#sum

提交回复
热议问题