2

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.

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
winnu
  • 95
  • 1
  • 2
  • 8

2 Answers2

4

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)
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • 1
    Dude, u r really really awesome... U explain things so good... Thanks a lot dude... Worked perfectly – winnu Mar 25 '16 at 08:44
  • @winnu Really?, nice to hear that because my English is not so good to express things as I want, I have edited various time my answer. I'm glad to help :) thanks for comment. – ElektroStudios Mar 25 '16 at 08:48
  • Yes dude Really... and btw i'm just wondering if u could tell me how do I insert a blank line – winnu Mar 25 '16 at 08:52
  • With: `String.Format("[restabs alignment={0}osc-tabs-left{0} responsive={0}false{0} tabcolor={0}#d1d1d1{0} seltabcolor={0}#000000{0}]{1}", qmQuotes, Environment.Newline)` (note the `{1}` at the end of the format) – ElektroStudios Mar 25 '16 at 08:54
  • what's ur timings here on this site, because I will post my questions only during that time when u r online... and I'm just wondering if i can message u on this site ??? – winnu Mar 25 '16 at 09:10
  • @winnu I don't know what to tell you, because some days I'm here, but some other days not, probably you could find me here at this time (its morning here), i check SO various times at day so really any specific hour. A chat is available in StackOverflow but I don't use it, sorry. https://chat.stackoverflow.com/ – ElektroStudios Mar 25 '16 at 09:17
2

Why complicate your life when you can use escaping quote ? You just have to double it...

Dim myString = "[restabs alignment=""osc-tabs-left"" responsive=""false"" tabcolor=""#d1d1d1"" seltabcolor=""#000000""]"
Martin Verjans
  • 4,675
  • 1
  • 21
  • 48