# removing vowels in a string



## giorgos_412 (Nov 26, 2010)

I'm trying a method to remove all the vowels from a string.I tried this code but it working the the case which i don't have two consecutive vowels:
code:


> public static String removeVowels(String str2){
> String vowels = "aeiuoyAEIOUY";
> StringBuffer newBuffer1 = new StringBuffer(str2);
> StringBuffer newBuffer2 = new StringBuffer(vowels);
> ...


For example if my method take a string str2= "The End of the World" it will return me "Th nd f th Wrld" , but if my method take a string str2="george" it will return me "gorg" without removing the "o".


----------



## TheOutcaste (Aug 8, 2007)

Welcome to TSG!

When you delete a character, the folowing characters shift to the left. When you remove the first e in george, the o becomes the 2nd character. You've already checked the 2nd character (e) and removed it, so the o gets skipped. You need to adjust the counter to take this into account.

I don't know why the last e isn't being removed; is it actually returning *gorge* or just *gorg*?


----------



## giorgos_412 (Nov 26, 2010)

just gerg,sorry theoutcast i wrote it wrong.thank you very much for your advice.i solve the problem by reducing by 1 my first counter every time that newBuffer1.deleteCharAt(counter1) takes place


----------

