gpt4 book ai didi

java - 将字符串添加到某些字符

转载 作者:行者123 更新时间:2023-12-01 13:48:42 24 4
gpt4 key购买 nike

为类做实验(不能使用 ARRAY )**它是一个语言转换器,我必须在每个元音后面加上“ub”我想知道如何在没有数组的情况下做到这一点到目前为止我已经有了,但它只是在字符串中的第二个字母后面添加了“ub”

private static String toUbbi(String word ) {            
String set = " ";
if (Vowel (word)){
set= word.substring(0)+ "ub"+word.substring(1) ;
set = word.substring(0,1)+ "ub"+word.substring(1);
}
return set;
}

private static boolean Vowel(String word ) {
String[] vowels ={ "a", "e", "i", "o", "u", "ue"} ;
//char x = word.charAt(0);
return (vowels.length !=-1);
}

最佳答案

String word = "test";
String[] vowels ={ "a", "e", "i", "o", "u"}
for (int i = (vowels.length - 1); i>=0; i-- ){

word = word.replaceAll(vowel[i], vowel[i].concat("ub"));
}

关于java - 将字符串添加到某些字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20137570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com