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

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...