I'm trying to include quotes into my string to add to a text box, i am using this code.
t.AppendText("Dim Choice" & count + " As String = " + "Your New Name is: & pt1 + "" & pt2 +" + vbNewLine)
but it doesnt work, i want it to output like so:
Dim Choice As String = "Your New Name is: NAME_HERE"
You have to escape the quotes. In VB.NET, you use double quotes - "":
t.AppendText("Dim Choice" + count.ToString() + " As String = ""Your New Name is: " + pt1 + " " + pt2 + """" + vbNewLine)
This would print as:
Dim Choice1 As String = "Your New Name is: NAME HERE"
Assuming count = 1 (Integer), pt1 = "NAME" and pt2 = "HERE".
If count
is not an Integer, you can drop the ToString() call.
In C#, you escape the " by using a \, like this:
t.AppendText("string Choice" + count.ToString() + " = \"Your New Name is: " + pt1 + " " + pt2 + "\"\n");
Which would print as:
string Choice1 = "Your new Name is: NAME HERE";
As Tim said, simply replace each occurrence of "
inside the string with ""
.
Furthermore, use String.Format
to make the code more readable:
t.AppendText( _
String.Format( _
"Dim Choice{0} As String = ""Your New Name is: {1} {2}""{3}", _
count, pt1, pt2, vbNewLine)
Depending on the type of your t
, there might even be a method that supports format strings directly, i.e. perhaps you can even simplify the above to the following:
t.AppendText( _
"Dim Choice{0} As String = ""Your New Name is: {1} {2}""{3}", _
count, pt1, pt2, vbNewLine)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With