Replace problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AZNewsh

    #1

    Replace problem

    I am storing HTML in an oracle database, this is loaded from a textbox
    in a webpage, I convert ' to ' ' using the code below:

    foo.Replace("'" , "''").Replace(" &", "'||'&'||'" )

    this works just fine, then when I retrieve the text from the database
    and display it in a webpage, I convert it back using:

    objdr.Item("foo ").Replace("''" , "'").Replace("' ||'&'||'", "&")

    For some reason this then ends up converting ' ' not to ' but to an
    upside down question mark ¿, not sure of the correct terminology for
    that.

    Any thoughts on why it is doing this and how to prevent it?

    Thanks in advance

  • hayworth@hotmail.com

    #2
    Re: Replace problem

    I'm not exactly sure what you're trying to do -- all your quotes are
    running together. Are you trying to convert one single quote
    (apostrophe) to two single quotes (two apostrophes) or one double quote
    mark? Anyway, to get a double quote in VB you need to do (or can do)
    this very strange thing.
    dim strDoubleQuote as String
    strDoubleQuote = """" ' 4 double quotes evaluates to a single
    double quote.
    strSingleQuote = "'" ' Apostrophe encased in double quotes.
    Perhaps that will help you. Or you can use the CHR function with the
    proper ASCII code for the quote you want.

    So to replace singles by doubles do
    foo = Replace(foo, strSingleQuote, strDoubleQuote)

    Comment

    • Cerebrus

      #3
      Re: Replace problem

      Hi,

      Actually I think I have an idea what AZNewsh is doing. He is using a
      familiar technique to clean up his HTML before it enters the database.
      Something similar to preventing SQL Injection, I think.

      So, he is converting a single quote to 2 single quotes, and when
      retrieving data back from the database, he is converting the 2 single
      quotes back to a single quote.

      Though I have no idea why he could be getting an "inverted question
      mark" (Yes, that's what it's called, according to Charmap.)

      Regards,

      Cerebrus.

      Comment

      • AZNewsh

        #4
        Re: Replace problem

        Correct that is exactly what I am trying to do, it works fine in so far
        as it cleans up the quotes before entering the database. I have since
        been informed that it doesn't actually replace with 2 single quotes,
        just fools Oracle somehow, so i actually don't need to reverse it, it
        does however even look like a an inverted question mark even in the
        database when viewed through Toad, haven't tried SQL Plus but expect
        the same, I did put a replace in place that will now convert the
        inverted question mark back to an apostrophe, when selecting and this
        works but seems like a rather none elegant solution

        Any thoughts?

        AZNewsh

        Comment

        • Homer J Simpson

          #5
          Re: Replace problem


          "AZNewsh" <gn@dana.ucc.na u.edu> wrote in message
          news:1144105532 .700634.283530@ i39g2000cwa.goo glegroups.com.. .
          [color=blue]
          > Correct that is exactly what I am trying to do, it works fine in so far
          > as it cleans up the quotes before entering the database. I have since
          > been informed that it doesn't actually replace with 2 single quotes,
          > just fools Oracle somehow, so i actually don't need to reverse it, it
          > does however even look like a an inverted question mark even in the
          > database when viewed through Toad, haven't tried SQL Plus but expect
          > the same, I did put a replace in place that will now convert the
          > inverted question mark back to an apostrophe, when selecting and this
          > works but seems like a rather none elegant solution
          >
          > Any thoughts?[/color]

          ISTR that Oracle has weird notions about some characters, including
          wildcards. It also has optional character map pages. Don't know if it helps.


          Comment

          Working...