1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Java help - Replace all if string contains multiple substrings

Discussion in 'JavaScript' started by bobocheez, Aug 30, 2010.

  1. #1
    So there's a really old guy teaching Java at my college, and I have not learned a thing. He set a 1 day deadline to write something that we don't even know about. The book is worthless as well.

    Here we're inputting a string and searching for 3 words to take out. However, it this only works if all 3 words are inserted. I can't even think straight anymore...after 2 straight hours of staring at my screen.



    		Scanner keyboard = new Scanner(System.in);
    		String v1 = keyboard.nextLine();
    		String dog = "dog";
    		String cat = "cat";
    		String llama = "llama";
    				
    		String result = v1.replaceAll("(?i)dog ", "");
    		String result2 = result.replaceAll("dog ", "");
    		
    		String result3 = result2.replaceAll("(?i)cat ", "");
    		String result4 = result3.replaceAll("cat", "");
    		
    		String result5 = result4.replaceAll("(?i)llama ", "");
    		String result6 = result5.replaceAll("llama ", "");
    		
    		System.out.println(result6);
    Code (markup):
    This is so similar to PHP but so many different exceptions >.< and tight rules.

    Thanks for your help :)
     
    bobocheez, Aug 30, 2010 IP