How to replace " with " character in String

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jmash
    New Member
    • Oct 2007
    • 6

    How to replace " with " character in String

    Suppose I have the following string whch is part of an xml string:
    String s= "Script Id="Test&q uot; "

    And I need to get
    s= "Script Id="Test" "

    Can anyone tell me how this can acheived?

    Thanks,
    jmash
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Have you tried the Replace?

    String s= "Script Id="Test&q uot; ";
    s = s.Replace("&quo t;", "\"");

    backslash is used as an escape character.
    Note the 3 quotation marks in the second argument of the Replace method

    Comment

    • DrBunchman
      Recognized Expert Contributor
      • Jan 2008
      • 979

      #3
      Originally posted by jmash
      Suppose I have the following string whch is part of an xml string:
      String s= "Script Id="Test&q uot; "

      And I need to get
      s= "Script Id="Test" "

      Can anyone tell me how this can acheived?

      Thanks,
      jmash
      No problem JMash,

      To insert a double quotation inside a string you need to use two double double quotation marks next to each other. So you would replace all instances of &quot with "". Try this:

      s = s.Replace("&quo t", """")

      This little rule about quote marks applies to apostrophe's as well where they are used as string delimiters (for example in SQL) and is an important thing to be aware of.

      Give this a try and let me know if it helps,

      Dr B

      Comment

      Working...