如何在 Visual Basic 中转义引号 [英] How to escape a quotation mark in Visual Basic

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

问题描述

所以基本上我试图在 VB 中转义引号.

so basically I'm trying to escape a quotation mark in VB.

我有以下代码:

RichTextBox2.Text = "<furnitype id=" + TextBox3.Text + "

我需要:

RichTextBox2.Text = "<furnitype id="" + TextBox3.Text + ""

所以基本上 textbox3 中的文本需要引用,但我不能这样做,因为它需要引用来添加文本.

So basically the text that is within the textbox3 needs to be quoted, but I can't do so since it requires quotation to add text.

推荐答案

你用另一个双引号转义一个双引号,例如

You escape a double quote with another double quote, e.g.

Console.WriteLine("He said ""Hello"" to me.")

将显示:

他对我说你好".

就你而言,我认为你的代码应该是这样的:

In your case, I think you code should be something like this:

RichTextBox2.Text = "<furnitype id=""" & TextBox3.Text & """>"

我倾向于建议使用 String.Format 或字符串插值来使代码更清晰:

I would tend to suggest using String.Format or string interpolation to make the code clearer though:

RichTextBox2.Text = String.Format("<furnitype id=""{0}"">", TextBox3.Text)

或:

RichTextBox2.Text = $"<furnitype id=""{TextBox3.Text}"">"

请注意,字符串插值仅在 VB 2015 或更高版本中可用.

Note that string interpolation is only available in VB 2015 or later.

这篇关于如何在 Visual Basic 中转义引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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