Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

remove all vowels from any given string  RSS feed

 
Konrad Cetes
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create a program that will remove all vowels from any given string then eventually do the same but with consonants. So far all I've been able to do is remove the rest of the string will replacing the vowels. I am trying to do this with out using an replace commands. Any ideas or help would be much appreciated.





Result:
Enter a word:
Hello
*
*
*
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Konrad Cetes wrote: So far all I've been able to do is remove the rest of the string will replacing the vowels.


There is no "remove", "replacing", or any modification of a string in the code that you have shown.

Henry
 
Charles Nduka
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why don't you try out "
       
int max = searchMe.length();
char ff = 'a';
int c = 0;

for (int i=0;i<max;i++){
if (searchMe.charAt(i) != ff)
c++;

continue;

} "
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Charles.

I couple of things about your posts: I know it's sometimes not possible to edit your posts, but if you notice something you want to change after hitting Submit, just post the line you want to change.  Don't quote the whole post -- quote only what you are changing. 

You can also prevent many mistakes by using the Preview button before you hit Submit in the Post Reply form.

Also, when posting code, please UseCodeTags (that's a link).
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can short the comparison like below:

for (int i = 0; i < word.length(); i++) {
   i f( "aeiou".indexOf( Character.toLowerCase(word.charAt(i)) ) >= 0 ) {
               //somework
   } else {
              //somework
   }
}
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please search this website; somebody else asked a very similar question a few days ago.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!