locked
Including quotation marks in a code-behind string? RRS feed

  • Question

  • User-651307469 posted

    Hi Guy's

    Silly question, I know....but how do you include quotation marks in a string ...like

    Dim ltrBeginHeader As New Literal

    ltrBeginHeader.Text = " <thead align="center" style="backtround-color:gray"> "

    This wont work because the quotation marks in the string interfere with the outer quotation marks......any ideas? :)

    Friday, July 25, 2008 8:11 AM

Answers

  • User-1544394188 posted

    The simpliest thing to do in this situation would be to use single quotes in your string literal:

    1    Dim ltrBeginHeader As New Literal
    2   
    3    ltrBeginHeader.Text = "<thead align='center' style='backtround-color:gray'>"

    If you must use quotation marks than you can use them by doubling them up (although sometimes you have to put 3 instead of two to make it work, just experiment):

    1    Dim ltrBeginHeader As New Literal
    2   
    3    ltrBeginHeader.Text = "<thead align=""center"" style=""backtround-color:gray"">"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 25, 2008 8:18 AM
  • User384031199 posted

    Use single quote character for the attribute values inside the html tag in your string.

    Hope this helps.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 25, 2008 8:19 AM
  • User-990694832 posted

    Use chr(34)

    stringbuilder.append("  .... ")

    stringbuilder.append(chr(34)) your opening quotes

    stringbuilder.append(" .....")   your string inbetween quotes

    stringbuilder.append(chr(34)) your closing quotes

    Hope this helps

    Also, this is not an issue is vs2008

    DK 

     

      

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 25, 2008 8:30 AM

All replies

  • User-1544394188 posted

    The simpliest thing to do in this situation would be to use single quotes in your string literal:

    1    Dim ltrBeginHeader As New Literal
    2   
    3    ltrBeginHeader.Text = "<thead align='center' style='backtround-color:gray'>"

    If you must use quotation marks than you can use them by doubling them up (although sometimes you have to put 3 instead of two to make it work, just experiment):

    1    Dim ltrBeginHeader As New Literal
    2   
    3    ltrBeginHeader.Text = "<thead align=""center"" style=""backtround-color:gray"">"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 25, 2008 8:18 AM
  • User384031199 posted

    Use single quote character for the attribute values inside the html tag in your string.

    Hope this helps.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 25, 2008 8:19 AM
  • User-990694832 posted

    Use chr(34)

    stringbuilder.append("  .... ")

    stringbuilder.append(chr(34)) your opening quotes

    stringbuilder.append(" .....")   your string inbetween quotes

    stringbuilder.append(chr(34)) your closing quotes

    Hope this helps

    Also, this is not an issue is vs2008

    DK 

     

      

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 25, 2008 8:30 AM
  • User-651307469 posted

    thank you very much, that worked like a charm.

    Nuwanda

    Friday, July 25, 2008 10:50 AM
  • User-158764254 posted

    if you double up the double-quote, you will get a single literal quote

    ltrBeginHeader.Text = " <thead align=""center"" style=""backtround-color:gray""> "
    
    
     
    Tuesday, July 29, 2008 9:50 PM
  • User-1719671795 posted

    I used both double quote and chrm(34) in ARRAY STRING but they did not work. The result is shown on aspx page correctly. But the code returns nothing.

    :(

    Tuesday, October 30, 2012 6:09 PM