Results 1 to 6 of 6
  1. #1
    7oclock is offline Member
    Join Date
    Feb 2009
    Posts
    9
    Rep Power
    0

    Default Help Replacing String

    Hello,
    Ok, I have a String variable name "InfoCon" which contains some string. Now what I need to do is replace string " in InfoCon to '. I can't do InfoCon.replaceAll(""", "'"); , can I? So, Please help me...

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    10

    Default huh?

    No sure I understand... you mean:
    Java Code:
    String infoCon = "some string";
    infoCon = "another string";
    I really not understanding your question.

    EDIT:
    OK.. I reread your post a few more times... do you mean:
    String infoCon = "some string";
    infoCon = "'";
    Luck,
    CJSL
    Last edited by CJSLMAN; 02-13-2009 at 03:28 PM. Reason: I think I might have nderstood...
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    7oclock is offline Member
    Join Date
    Feb 2009
    Posts
    9
    Rep Power
    0

    Default

    That won't work. I mean replacing a letter not whole string. For example in "Apple" if we replace A to B then we get "Bpple". In the same way, I want to replace " (double quotes ) to ' (single quotes) in a string.
    Last edited by 7oclock; 02-13-2009 at 03:47 PM.

  4. #4
    l_m_b is offline Member
    Join Date
    Feb 2009
    Posts
    7
    Rep Power
    0

    Default

    Java Code:
    String infoCon = "My test \"program\"";
    infoCon = infoCon.replace('"', '\'');
    System.out.println(infoCon);

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    10

    Default Stringbuilder

    or you can use the StringBuilder class instead of String. It has insert and replce methods:
    StringBuilder (Java Platform SE 6)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  6. #6
    7oclock is offline Member
    Join Date
    Feb 2009
    Posts
    9
    Rep Power
    0

    Default

    Adding a backlash infront of double quote worked. Thank you l_m_b and CJSLMAN.

Similar Threads

  1. replacing characters???
    By manda147 in forum New To Java
    Replies: 2
    Last Post: 11-29-2008, 09:19 AM
  2. replacing array values
    By Jononomous in forum New To Java
    Replies: 1
    Last Post: 05-22-2008, 03:27 PM
  3. Replies: 1
    Last Post: 05-07-2008, 01:19 AM
  4. Replacing at an index
    By bugger in forum New To Java
    Replies: 2
    Last Post: 01-29-2008, 07:33 AM
  5. splitting string and replacing
    By itsme in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 04:08 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
  •