Regular expression in java in String class

Discussion in 'Mac Programming' started by Nobita, Mar 21, 2009.

  1. macrumors 6502

    Joined:
    Oct 5, 2008
    Location:
    La la land
    #1
    Hello everyone,

    I'm in a middle of confusion now. I'm trying to use the String java class to replace all occurences of word in sub to word in put. The problem is, this doesn't work:

    String sub = "Hello";
    String put = "Hi";

    line.replaceAll(sub, put);

    I've been searching through google and other stuff, but I still couldn't understand what went wrong, please help!
     
  2. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #2
    Hi

    replaceAll returns a new string with the results of the replacement.

    b e n
     

Share This Page