Removes a specific character from a string in Java

For example, when we specify the character to be deleted as aeiou, we give a string of "vowel war": Hawaii vs. groney, which should convert the string to vwls: HW vs grzny

This problem is found in the book Programming interviews exposed This has been explained in C, but I am interested in Java

Solution

A simple method is to use regular expressions:

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

Some Java class library API documents:

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>