Results 1 to 3 of 3

Thread: Help!!!!!! Project due Tomorrow!!

Hybrid View

  1. #1
    Join Date
    Nov 2009

    Help!!!!!! Project due Tomorrow!!

    I have a project that i have no idea where to start with.

    The question is - Write a program that reads a line of text from the keyboard and then displays it without any punctions. Hint: create a string or punctuation character ",.:;'?!\"()" test to see if the next character of the line is not a substring of the punctuation string, then add it to the new string that does not contain punctuation.

    Any help is appreciated

  2. #2
    Join Date
    Sep 2009
    No need to deal with it character by character or use substring etc. Basic regex will suffice. I'll leave it up to you to figure out how to read from keyboard etc.

    public class Test {
    	public static void main(String[] args) {
    		try {
    			String s = "This is a sentence.  Here is a comma ','.  And a question mark '?'.  And some more crap: ,.:;'?!\"()";
    			System.out.println("Before: " + s);
    			s = s.replaceAll("[,.:;'?!\"()]", "");
    			System.out.println("After: " + s);
    		} catch (Exception e) {
    PS. There are more punctuation characters than you have listed but I have just used the ones you mentioned.

  3. #3
    Join Date
    Nov 2009
    Thank you so much. this works so well and its a lot easier. i really appreciate it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center