Why double escape for apostrophe?

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

    #1

    Why double escape for apostrophe?

    Anyone know why the RowFilter has to be double-escaped? Anticipating names
    with apostrophes, a single escape does not provide the proper name to filter
    on.

    For example, this would cause an exception:
    Dim strname As String
    strname = txtContact.Text
    strname.Replace ("'", "''")
    dv.RowFilter = "ContactFullNam e='" + strname + "'"

    .... but this would provide the proper filter:
    dv.RowFilter = "ContactFullNam e='"" + strname + ""'"

    Note the comma before the double quotes on the inside before the apostrophe
    and the double quotes after the apostrophe on the outside.


  • Patrice

    #2
    Re: Why double escape for apostrophe?

    Use :
    strName=strName .Replace("'","' '")

    Keep in mind that strings are immutable i.e. are never changed that is the
    Replace *function* returns a new string. It doesn't change the existing
    string.

    ---
    Patrice


    "Earl" <brikshoe@newsg roups.nospama écrit dans le message de news:
    uYwiP%23wwHHA.8 40@TK2MSFTNGP03 .phx.gbl...
    Anyone know why the RowFilter has to be double-escaped? Anticipating names
    with apostrophes, a single escape does not provide the proper name to
    filter on.
    >
    For example, this would cause an exception:
    Dim strname As String
    strname = txtContact.Text
    strname.Replace ("'", "''")
    dv.RowFilter = "ContactFullNam e='" + strname + "'"
    >
    ... but this would provide the proper filter:
    dv.RowFilter = "ContactFullNam e='"" + strname + ""'"
    >
    Note the comma before the double quotes on the inside before the
    apostrophe and the double quotes after the apostrophe on the outside.
    >

    Comment

    • Earl

      #3
      Re: Why double escape for apostrophe?

      Thanks Patrice.

      "Patrice" <http://www.chez.com/scribe/wrote in message
      news:OnRxbCxwHH A.4568@TK2MSFTN GP03.phx.gbl...
      Use :
      strName=strName .Replace("'","' '")
      >
      Keep in mind that strings are immutable i.e. are never changed that is the
      Replace *function* returns a new string. It doesn't change the existing
      string.
      >
      ---
      Patrice
      >
      >
      "Earl" <brikshoe@newsg roups.nospama écrit dans le message de news:
      uYwiP%23wwHHA.8 40@TK2MSFTNGP03 .phx.gbl...
      >Anyone know why the RowFilter has to be double-escaped? Anticipating
      >names with apostrophes, a single escape does not provide the proper name
      >to filter on.
      >>
      >For example, this would cause an exception:
      >Dim strname As String
      >strname = txtContact.Text
      >strname.Replac e("'", "''")
      >dv.RowFilter = "ContactFullNam e='" + strname + "'"
      >>
      >... but this would provide the proper filter:
      >dv.RowFilter = "ContactFullNam e='"" + strname + ""'"
      >>
      >Note the comma before the double quotes on the inside before the
      >apostrophe and the double quotes after the apostrophe on the outside.
      >>
      >
      >

      Comment

      Working...