简单字符串的替换(把元音字母替换为“*”)

public class WordPlay {

    public String replaceVowels(String str) {
        String result="";
        str = str.toUpperCase();
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == 'A' || str.charAt(i) == 'O' || str.charAt(i) == 'E' || str.charAt(i) == 'U' || str.charAt(i) == 'I') {
               result = str.replaceAll("[A,O,E,I,U]", "*");
            }
        }
        return result;
    }


    public static void main(String []args){
        WordPlay wordPlay = new WordPlay();
        System.out.println(wordPlay.replaceVowels("hello world"));
    }
}
//下面链接为一位博主写的关于replace家族的分析
点击打开链接

你可能感兴趣的:(java,replaceAll,正则表达式,替换)