How to insert single quotes in double quotes in VB

2019-07-17 07:09发布

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>")

4条回答
可以哭但决不认输i
2楼-- · 2019-07-17 07:38

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

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

  • " & chr(34 ) & chr(34) & "" + BP1.Text + ". . . . .

  • 查看更多
    够拽才男人
    3楼-- · 2019-07-17 07:43

    It seems you used the wrong character for single quotation:

    objWriter.WriteLine("<li>" + "'" + "<em>" + BP1.Text + "</em>" + "'" + " ― " + "<strong>" + BPGB1.Text + "</strong>" + "</li>")
    
    查看更多
    放我归山
    4楼-- · 2019-07-17 07:45

    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>")
    
    查看更多
    再贱就再见
    5楼-- · 2019-07-17 07:53

    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)
    
    查看更多
    登录 后发表回答