如何在VB .NET中的双引号中插入单引号 [英] How to insert single quotes in double quotes in VB .NET

查看:193
本文介绍了如何在VB .NET中的双引号中插入单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在双引号内插入单引号... 像这样的"" .....开头的引号和像这样"" ...

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

我的代码:

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

推荐答案

第一:

您提到的字符不是单引号,而是双引号.

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

第二名:

Vb.Net 中,与 C#不同,字符串连接是使用&运算符进行的,避免使用+运算符,它将为您提供 意外结果 .

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.

Visual Studio 的代码编辑器会自动用通用的双引号替换您提到的字符,但是,知道Unicode引用后,您可以在执行时获取特定的字符,然后将它们连接起来像往常一样或使用 String.Format() 方法:

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)

这篇关于如何在VB .NET中的双引号中插入单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆