Results 1 to 5 of 5

Thread: problem with double and single quotes in string

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    3

    problem with double and single quotes in string

    Hi,

    I have a problem with double and single quotes in a string.

    I have a textbox where i take a string from.
    In the textbox are double quotes and single quotes quotes.
    Problem is that if i return the string all the single quotes are replaced by double quotes.
    How can i get it to keep the single quotes as single quotes?

    Thanks in advance

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: problem with double and single quotes in string

    Single quotes don't turn into double quotes on their own. Either it's not happening or your code is making it happen. We're going to need more information on the specifics of your application.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    3

    Re: problem with double and single quotes in string

    this is my code i'm using.
    i have a webpage with 2 textboxes and a button.

    Code:
    If page.Ispostback then
       dim oCodeZonder as string
       dim oCodeMet as new system.text.stringbuilder
       dim oNewLine as integer
       dim teller as integer = 1
       htmlDoc.GetElementbyId("codeVoorTry").innerHtml = page.Request("codeVoorTry")
       oCodeZonder = page.Request("codeVoorTry")
       oCodeMet.Append("Try" & vbcrlf & "errNum = " & teller.ToString & vbCrLf)
       dim uitgaan as boolean
       uitgaan = false
       While uitgaan <> true
          teller = teller+1
          oNewline = oCodeZonder.IndexOf(vbCrLf)
          if oNewLine = -1 then
             uitgaan = true
             oCodeMet.Append(oCodeZonder & vbCrLf)
             oCodeMet.Append("errNum = " & teller.ToString & vbCrLf)
             oCodeMet.Append("catch ex as exception" & vbCrLf & "throw new exception (errNum & ""-"" & ex.Message)")
             oCodeMet.Append(vbCrLf & "end try")
          else
             oCodeMet.Append(Left(oCodeZonder, oNewLine))
             oCodeMet.Append(vbCrLf & "errNum = " & teller.ToString)
             oCodeZonder = oCodeZonder.Remove(0, oNewLine+1)
          end if    
       end while
       htmlDoc.GetElementbyId("codeNaTry").innerHtml = oCodeMet.tostring
    end if
    if for example i put this in the textbox:

    oDetail.append("<tr><td>Section name</td><td><input type='text' id='afdelingNaamEng' name='afdelingNaamEng' value='" & cfc("afdelingnaam",1).ToString & "' runat='server'></td></tr>")
    oDetail.append("<tr><td>Afdeling naam</td><td><input type='text' id='afdelingNaamNed' name='afdelingNaamNed' value='" & cfc("afdelingnaam",2).ToString & "' runat='server'></td></tr>")

    it gives back this

    oDetail.append("<tr><td>Section name</td><td><input type="text" id="afdelingNaamEng" name="afdelingNaamEng" value=""></td></tr>")
    oDetail.append("<tr><td>Afdeling naam</td><td><input type="text" id="afdelingNaamNed" name="afdelingNaamNed" value=""></td></tr>")

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: problem with double and single quotes in string

    Right, so it's not your text box. The lack of any other information in your first post implies that it's your own TextBox in a WinForms application. It's important to provide the whole story.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    3

    Re: problem with double and single quotes in string

    owk so finally know what the problem is. apparantly if you write a string from vb.net to an aspx page the string gets changed.
    the chars having problems are <, >, ", '. what i did to prevent this was using string.replace to replace these chars to html code &quot; etc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width