replace double inverted commas into slash double inverted commas in string

Discussion in 'Java' started by AviraM, Sep 28, 2006.

  1. AviraM

    AviraM Guest

    hi all

    I have a var of String type
    the string include double inverted commas (") and I need to replace it
    into slash double inverted commas (\")

    example:
    original: "abc"de"
    result: "abc\"de"

    that problem came because I got the string from the databse and I need
    the string to make a query from the databae comparing as is but the
    all parse is illegal without change my string

    thanks all
    AviraM, Sep 28, 2006
    #1
    1. Advertising

  2. Re: replace double inverted commas into slash double inverted commasin string

    AviraM wrote:
    > hi all
    >
    > I have a var of String type
    > the string include double inverted commas (") and I need to replace it
    > into slash double inverted commas (\")
    >
    > example:
    > original: "abc"de"
    > result: "abc\"de"
    >
    > that problem came because I got the string from the databse and I need
    > the string to make a query from the databae comparing as is but the
    > all parse is illegal without change my string
    >
    > thanks all
    >


    If I were better with regex I could probably do this in one step :).

    public class test8 {
    public static void main(String[] args) {
    String str = "\"abc\"def \"13s\"";
    System.out.println(str);
    str = str.replaceAll("\"","\\\\\"");
    System.out.println(str);
    str = str.replaceAll("^\\\\\"(.*)\\\\\"$","\"$1\"");
    System.out.println(str);
    }
    }

    --

    Knute Johnson
    email s/nospam/knute/
    Knute Johnson, Sep 28, 2006
    #2
    1. Advertising

  3. Manish Pandit, Sep 28, 2006
    #3
    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. Jon Maz
    Replies:
    3
    Views:
    1,641
    Jon Maz
    Feb 13, 2004
  2. destroooooy
    Replies:
    4
    Views:
    653
    Arnaud Delobelle
    Apr 29, 2008
  3. Chris Rebert

    Re: string replace for back slash

    Chris Rebert, Feb 5, 2009, in forum: Python
    Replies:
    0
    Views:
    416
    Chris Rebert
    Feb 5, 2009
  4. Replies:
    8
    Views:
    268
    A. Sinan Unur
    May 25, 2006
  5. Replies:
    3
    Views:
    150
    Jeremy
    Jul 7, 2006
Loading...

Share This Page