I should write a function that excludes certain letters (char) of a sentence (String). I basically also did that but the problem is I only managed to cut out the 1st appearance of the letter in the sentence.
public static void main (String[] args) {
String text = "This text may be readable without vowels!";
String letters = "aeiou";
Out.println(removeLetters(text, letters));
}
public static String removeLetters(String text, String letters) {
char c = 'f';
String remover = text;
for (int i=0; i<letters.length(); i++) {
c = letters.charAt(i);
remover = removeChar(remover, c);
}
return remover;
}
public static String removeChar(String text, char c) {
int i1 = text.indexOf(c);
String result = text.substring(0, i1) + text.substring(i1+1);
return result;
}
How do I need to change the last function removeChar
to get all appearances of a letter cut out? It might not be that hard to find all indexes but the real struggle is to put the substrings together afterwards, so that you still only have the one sentence left just without the certain letters. Because the more indexes you have the more different substrings you need to add together if I understood it correctly.
Currently I get this.
Ths txt my be readable witht vowels!
And the aim would be to get here:
Ths txt my b rdbl witht vwls!