Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Removing Vowels and spaces help!
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Krocker




PostPosted: Wed Dec 14, 2011 1:29 pm   Post subject: Removing Vowels and spaces help!

hey guys, i need help with this assignment for school, i need to get an input word which the program will then remove all the vowels and shorten the words. i got the part were it removes the vowels, but i dont know how to remove the spaces left by deleting the letter. i tried to use String.trim() method, but that only removed the spaces between the words. Note that the user only enters in one word. heres my script:


code:
import hsa.Console;

public class StudentsAreComplaining
{
    public static void main (String[] args)
    {
        Console c = new Console ("Students Are Complaining!!");
        String word;
        String trim;
        char repeat = 'a';

        while (repeat == 'a')
        {
            c.print ("Please enter the word you want to change: ");
            word = c.readLine ();
            word = word.replace ('a', ' ');
            word.replace ('e', ' ');
            word.replace ('i', ' ');
            word.replace ('o', ' ');
            word.replace ('u', ' ');
            word.replace ('y', ' ');
            c.println (word);
            repeat = c.getChar ();

            c.clear ();
        }

    }
}


Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Dec 14, 2011 1:53 pm   Post subject: RE:Removing Vowels and spaces help!

First, I'm pretty sure (without running it) that your code doesn't replace e, i, o, u or y. It probably works with 'a' just fine though.

There are a few straightforward ways to do this, depending on what the assignment wants you to do.

First, you could use replace(String,String), which will let you replace some string with some other string, such as replacing all "a" with "" (empty string).

Second, you could use replaceAll(String,String) which lets you replace letters based on a regular expression. It's a little neater, assuming you know regular expressions.

Third, you could construct a new String one-character-at-a-time from the input String, skipping vowels. If this is an introductory course, that's probably what you're supposed to be doing.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: