String Replace single quote with \'

Discussion in 'Java' started by jacky, Jun 14, 2004.

  1. jacky

    jacky Guest

    Any way to replace a String with single quote with \' ?
    e.g. June's Menu --> June\'s Menu

    Thanks
    June
    jacky, Jun 14, 2004
    #1
    1. Advertising

  2. <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String)>


    On 14.06.2004 11:18 jacky wrote:

    > Any way to replace a String with single quote with \' ?
    > e.g. June's Menu --> June\'s Menu
    >
    > Thanks
    > June
    Thomas Kellerer, Jun 14, 2004
    #2
    1. Advertising

  3. jacky

    VisionSet Guest

    "jacky" <> wrote in message
    news:...
    > Any way to replace a String with single quote with \' ?
    > e.g. June's Menu --> June\'s Menu
    >


    June\\'s Menu

    Single quote is irrelevent, unless I'm misunderstanding you.

    --
    Mike W
    VisionSet, Jun 14, 2004
    #3
  4. jacky

    Roedy Green Guest

    On Mon, 14 Jun 2004 12:19:21 +0100, "VisionSet" <>
    wrote or quoted :

    >> Any way to replace a String with single quote with \' ?
    >> e.g. June's Menu --> June\'s Menu


    you don't have to except inside single char literals.

    To change " to \" see http://mindprod.com/quoter.html

    Tell it you want to convert text to Java string literals.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Jun 14, 2004
    #4
  5. jacky

    jAnO! Guest

    "jacky" <> wrote in message
    news:...
    > Any way to replace a String with single quote with \' ?
    > e.g. June's Menu --> June\'s Menu
    >
    > Thanks
    > June


    check API.

    Class String, method replaceAll
    jAnO!, Jun 14, 2004
    #5
  6. jacky

    Alan Moore Guest

    On 14 Jun 2004 02:18:51 -0700, (jacky) wrote:

    >Any way to replace a String with single quote with \' ?
    >e.g. June's Menu --> June\'s Menu
    >
    >Thanks
    >June


    str = str.replaceAll("'", "\\\\'");

    The backslash serves as an escape character both for Java String
    literals and for the replacement string, so you have to use four of
    them to make one appear in the output.
    Alan Moore, Jun 15, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    13,194
  2. Eric Layman
    Replies:
    3
    Views:
    624
    Rad [Visual C# MVP]
    Apr 14, 2007
  3. Evan
    Replies:
    1
    Views:
    388
    Marc 'BlackJack' Rintsch
    Nov 4, 2008
  4. Evan
    Replies:
    3
    Views:
    517
    Marc 'BlackJack' Rintsch
    Nov 4, 2008
  5. vikrant
    Replies:
    8
    Views:
    359
    vikrant
    May 17, 2007
Loading...

Share This Page