Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

vb.net - How to escape a quotation mark in Visual Basic

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

I have the following code:

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

And I need:

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

will display:

He said "Hello" to me.

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

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

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)

or:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...