Search code examples
.netvb.netstring-formattingquotation-marks

Displaying Quotation Marks "


I'm trying to get the quotation marks as they are... to be displayed when creating a text file. And for that I'm using the following code.

When I'm writing code in the Visual Studio, I'm not seeing any errors with the following code but when I'm trying to debug... then I'm getting an error.

Can anyone tell me what's going on, what am I doing wrong here.

Dim qmQuotes As Char = Convert.ToChar(&H2022) ' "

 Dim Restabs As String =
        String.Format("[restabs alignment={1}osc-tabs-left{1} responsive={1}false{1} tabcolor={1}#d1d1d1{1} seltabcolor={1}#000000{1}]", qmQuotes)

Dim objWriter As New System.IO.StreamWriter("d:\value1.txt", True)
    objWriter.WriteLine(Restabs)

Btw My Desired output is

[restabs alignment="osc-tabs-left" responsive="false" tabcolor="#d1d1d1" seltabcolor="#000000"]

Thank You.


Solution

  • Seems that you want to use this time the common double quotes, then you could use the character constant:

    Dim qmQuotes As Char = ControlChars.Quote 
    

    Also, the problem in the code that you've provided is that you are using a non-existent argument index of {1} in your String.Format, since Vb.Net index is zero-based, you should use {0} to insert the first argument passed to the parameter array.

    String.Format("[restabs alignment={0}osc-tabs-left{0} responsive={0}false{0} tabcolor={0}#d1d1d1{0} seltabcolor={0}#000000{0}]", qmQuotes)