2

I'm trying to insert single Quotation marks inside a double quotation marks... Beginning Quotation mark like this "“" ..... and ending Quotation mark like this "”" ...

My code:

objWriter.WriteLine("<li>" + "“" + "<em>" + BP1.Text + "</em>" + "”" + " ― " + "<strong>" + BPGB1.Text + "</strong>" + "</li>")
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
winnu
  • 95
  • 1
  • 2
  • 8

4 Answers4

1

1st:

The characters that you mentioned are not a single quote, are a double quote.

2nd:

In Vb.Net, unlike C#, string concatenations are made with the & operator, avoid using the + operator, it will give you unexpected results in some scenarios.


The Visual Studio's code editor automaticaly replaces the characters that you've mentioned with a common double quote, however, knowing the Unicode references you can get the specific characters at execution time then concat them as normally or using the String.Format() method in this way:

Dim lQuotes As Char = Convert.ToChar(&H201C) ' “
Dim rQuotes As Char = Convert.ToChar(&H201D) ' ”

Dim str As String = String.Format("{0}Hello World{1}", lQuotes, rQuotes)

Console.WriteLine(str) ' “Hello World”

UPDATE

An example with the string that you've provided:

Dim lQuotes As Char = Convert.ToChar(&H201C) ' “
Dim rQuotes As Char = Convert.ToChar(&H201D) ' ”

Dim str As String =
    String.Format("<li>{0}<em>{2}</em>{1} ― <strong>{3}</strong></li>",
                  lQuotes, rQuotes, BP1.Text, BPGB1.Text)

objWriter.WriteLine(str)
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • Is it possible for you to show this result in the code that I've given in my question ??? Becoz I'm really novice to the .Net – winnu Mar 19 '16 at 10:02
  • I'm sorry but I don't really understand why u have used {0}{2}{1}{3} and i'm seeing that there's no objWriter.WriteLine code, I really want this inorder to write to a text file... I'm a complete novice here so I'm sorry – winnu Mar 19 '16 at 10:17
  • The `{n}` means the parameter index after the string format, so `{0}` = lQuotes, `{1}` = rQuotes, `{2}` BP1.Text and `{3}` = BPGB1.Text, the values are inserted at the position on where are written those `{n}` in the string format. About the Stream, you just should do: `objWriter.WriteLine(str)` with the resulting string. – ElektroStudios Mar 19 '16 at 10:22
  • Wowww... That worked like wonders... It's exactly what I want ... Thanks dude... You are the genius – winnu Mar 19 '16 at 10:31
  • @winnu You're welcome to StackOverflow :). I'm glad to help. but please remember to mark my answer as accepted if it solved your doubts. thanks. – ElektroStudios Mar 19 '16 at 10:33
0

It seems you used the wrong character for single quotation:

objWriter.WriteLine("<li>" + "'" + "<em>" + BP1.Text + "</em>" + "'" + " ― " + "<strong>" + BPGB1.Text + "</strong>" + "</li>")
ms_dos
  • 92
  • 10
  • I used the right characters, but May be i said wrongly in my question... I really meant the double quotations – winnu Mar 19 '16 at 10:04
0

not sure if this works or not:

objWriter.WriteLine("<li>" & "““" & "<em>" + BP1.Text + "</em>" + "””" + " ― " + "<strong>" + BPGB1.Text + "</strong>" + "</li>")

or maybe even this

objWriter.WriteLine("<li>" & ““““ & "<em>" + BP1.Text + "</em>" + ”””” + " ― " + "<strong>" + BPGB1.Text + "</strong>" + "</li>")
sam
  • 30
  • 2
  • I need a 1 double quotation inside the quotes... But I guess u have used 2 – winnu Mar 19 '16 at 10:18
  • @winnu The two double-quotes are used to escape the double quote char, the example is right when the intention is to insert a common double quote ("), but with your Unicode characters that will not work. – ElektroStudios Mar 19 '16 at 10:28
0

You will have to change the &"""" with chr(24)

so you would have something like this objWriter.WriteLine("

  • " & chr(34 ) & chr(34) & "" + BP1.Text + ". . . . .
  • BASit Bulbulia
    • 229
    • 3
    • 16