locked
Replacing double quote VB.NET 2008

    Question

  • Hi,

    I am needing to replace a double quote in a string.  If I'm not mistaken, this worked in VB.NET 2005, but is not working in 2008 (at least not in the aspx page with vb code).  I am trying to do two different things depending on the options that the user picks:

    1) mystring1 = mystring1.Replace("""", "") 'replaces " with nothing

    or

    2) mystring1 = mystring1.Replace(
    """", " "" ") 'adds a space to each side of double-quotes

    I even used mystring1.contains("""") .... it's not finding the quotation mark.

    Any ideas?

    Sunday, September 21, 2008 10:00 PM

Answers

  •   Try using the char version of the double quote to do the replace.  I can't think of why your previous code does not work in 2008 but perhaps this will be a workaroun until you figure it out.

    mystring1 = mystring1.Replace(Chr(34), String.Empty)

    • Marked as answer by Xingwei Hu Thursday, September 25, 2008 3:42 AM
    Sunday, September 21, 2008 10:45 PM
  • Thanks all for your responses.  I wrote up a little for loop to spit out the chr values for char(30)-chr(150) and found that the character was Chr(147), so I ended up using:

    mystring1 = mystring1.Replace(Chr(147), "")

    and 

    mystring1 = mystring1.Replace(Chr(147), " "" ")

    Thanks again (specifically Dig-Boy... your post pointed me toward what I needed).

    Sunday, September 21, 2008 11:48 PM
  • Hi Daniel,

    You may find the following tables and internet pages useful.>>

    http://asciitable.com/

     

    http://www.unicodetables.com/

     

    http://www.lookuptables.com/

     

    http://www.lookuptables.com/ebcdic_scancodes.php

     

    http://www.allconversions.com/

     


    Regrads,

    John


    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    • Marked as answer by Xingwei Hu Thursday, September 25, 2008 3:34 AM
    Tuesday, September 23, 2008 3:38 AM

All replies

  •   Try using the char version of the double quote to do the replace.  I can't think of why your previous code does not work in 2008 but perhaps this will be a workaroun until you figure it out.

    mystring1 = mystring1.Replace(Chr(34), String.Empty)

    • Marked as answer by Xingwei Hu Thursday, September 25, 2008 3:42 AM
    Sunday, September 21, 2008 10:45 PM
  •         Dim sQ As String = ControlChars.Quote 'single "
            Dim dQ As String = sQ & sQ 'double quote

    Sunday, September 21, 2008 10:47 PM
  • I just tried your first code example in VB2008 and got it to remove/replace the double quotes...  are you certain that you have double quotes in myString1?
    Sunday, September 21, 2008 10:50 PM
  •  After testing again, I found out that it does work fine!  The problem is that the user was using   instead of  "  Any suggestions on how to replace “ with " in the string?

    Thanks all!
    Sunday, September 21, 2008 11:47 PM
  • Thanks all for your responses.  I wrote up a little for loop to spit out the chr values for char(30)-chr(150) and found that the character was Chr(147), so I ended up using:

    mystring1 = mystring1.Replace(Chr(147), "")

    and 

    mystring1 = mystring1.Replace(Chr(147), " "" ")

    Thanks again (specifically Dig-Boy... your post pointed me toward what I needed).

    Sunday, September 21, 2008 11:48 PM
  • Daniel Osborne said:

     After testing again, I found out that it does work fine!  The problem is that the user was using   instead of  "  Any suggestions on how to replace “ with " in the string?

    Thanks all!

    What key(s) do you press to get  “

    Monday, September 22, 2008 2:07 AM
  • That would be Alt + 0147 (on the numberpad).  In this case, it was copied and pasted off a website into my web app.
    • Marked as answer by Xingwei Hu Thursday, September 25, 2008 3:35 AM
    • Unmarked as answer by Xingwei Hu Thursday, September 25, 2008 3:42 AM
    Monday, September 22, 2008 3:29 AM
  • Hi Daniel,

    You may find the following tables and internet pages useful.>>

    http://asciitable.com/

     

    http://www.unicodetables.com/

     

    http://www.lookuptables.com/

     

    http://www.lookuptables.com/ebcdic_scancodes.php

     

    http://www.allconversions.com/

     


    Regrads,

    John


    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    • Marked as answer by Xingwei Hu Thursday, September 25, 2008 3:34 AM
    Tuesday, September 23, 2008 3:38 AM