Results 1 to 4 of 4
  1. #1
    danoc93 is offline Member
    Join Date
    Apr 2012
    Posts
    37
    Rep Power
    0

    Default String replaceAll doesn't work!!!

    Hello everybody, I have a problem, I am using a Jtextpane for a chat app... the problem is that I need to replace the :) :( :/ etc expressions to <img src='image.gif'> for example...

    I tried using replaceAll method:

    message.replaceall(":)", "<img src='image.gif'>");
    It didn't work at all... it just cleared the string...

    message.replaceall("://)", "<img src='image.gif'>");
    Didn't work either

    message.replaceall("//://)", "<img src='image.gif'>");
    That didn't clear the string, but it didn't replace anything...

    How can I do it???

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: String replaceAll doesn't work!!!

    Are you using the return value or discarding it?

    Also, see BB Code List - Java Programming Forum

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    danoc93 is offline Member
    Join Date
    Apr 2012
    Posts
    37
    Rep Power
    0

    Default Re: String replaceAll doesn't work!!!

    Apparently replaceAll doesn't replace the chars in the same string but it generates a new string instead...

    I had it fixed by doing this:
    message = message.replaceall(":)", "<img src='image.gif'>");

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: String replaceAll doesn't work!!!

    And that is because Strings are immutable.
    They cannot be changed.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Why doesn't this work?
    By mailman in forum Java Applets
    Replies: 5
    Last Post: 01-10-2012, 01:01 PM
  2. Replies: 1
    Last Post: 10-08-2011, 05:41 AM
  3. Jar doesn't work
    By mad72584 in forum New To Java
    Replies: 35
    Last Post: 08-07-2011, 05:22 PM
  4. Replies: 2
    Last Post: 04-25-2011, 04:13 PM
  5. Regular Expressions and String.replaceAll()
    By meta1203 in forum New To Java
    Replies: 1
    Last Post: 11-24-2010, 11:41 PM

Posting Permissions

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