Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. StringBuilder ' escape sequence

StringBuilder ' escape sequence

Scheduled Pinned Locked Moved C#
helpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StyleGuide
    wrote on last edited by
    #1

    Hi there, Can anyone suggest the best way, or point me in the direction of, escaping or qualifying an ' (apostrophe) character within a StringBuilder? Unsurprisingly, I get a 'Missing operand after' error with the following:

    sb = "LastName = 'O'Brien'"

    Thanks Jon

    B 1 Reply Last reply
    0
    • S StyleGuide

      Hi there, Can anyone suggest the best way, or point me in the direction of, escaping or qualifying an ' (apostrophe) character within a StringBuilder? Unsurprisingly, I get a 'Missing operand after' error with the following:

      sb = "LastName = 'O'Brien'"

      Thanks Jon

      B Offline
      B Offline
      Bekjong
      wrote on last edited by
      #2

      StringBuilder sb = new StringBuilder(@"LastName = 'O'Brien'");

      Standards are great! Everybody should have one!

      S 1 Reply Last reply
      0
      • B Bekjong

        StringBuilder sb = new StringBuilder(@"LastName = 'O'Brien'");

        Standards are great! Everybody should have one!

        S Offline
        S Offline
        StyleGuide
        wrote on last edited by
        #3

        Thanks for this Bekjong, Sorry - I forgot to say I am getting the error on this line:

        namesBindingSource.Filter = sb.ToString();

        Thanks Jon

        D V 2 Replies Last reply
        0
        • S StyleGuide

          Thanks for this Bekjong, Sorry - I forgot to say I am getting the error on this line:

          namesBindingSource.Filter = sb.ToString();

          Thanks Jon

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Following code gives me no error :confused: BindingSource o = new BindingSource(); StringBuilder s = new StringBuilder("LastName = 'O'Brien'", 50); o.Filter = s.ToString(); Am I missing something?

          Avoid Google. Use Blackle[^]

          S 1 Reply Last reply
          0
          • S StyleGuide

            Thanks for this Bekjong, Sorry - I forgot to say I am getting the error on this line:

            namesBindingSource.Filter = sb.ToString();

            Thanks Jon

            V Offline
            V Offline
            Vikram A Punathambekar
            wrote on last edited by
            #5

            In SQL, you have to prefix single quotes with single quotes. yourQuery = "SELECT * FROM Grades WHERE StudentName = 'Scarlett O ''Hara'"

            Cheers, Vikram.


            The hands that help are holier than the lips that pray.

            1 Reply Last reply
            0
            • D dan sh

              Following code gives me no error :confused: BindingSource o = new BindingSource(); StringBuilder s = new StringBuilder("LastName = 'O'Brien'", 50); o.Filter = s.ToString(); Am I missing something?

              Avoid Google. Use Blackle[^]

              S Offline
              S Offline
              StyleGuide
              wrote on last edited by
              #6

              Thanks Vikram, d@nish, Thanks for the tip Vikram. d@anish - Yes you're right, however I get the error when applied to my namesBindingSource Thanks Jon

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups