I have to use a quote in a string variable. How do I assign it to a string without it ending the string altogether? If someone has the Ascii numder for it that would help as well.
Printable View
I have to use a quote in a string variable. How do I assign it to a string without it ending the string altogether? If someone has the Ascii numder for it that would help as well.
Please try this:
strMyString = Chr$(34) & "My Text" & Chr(34)
Hope it helps.
Chr$(34) will give you "
but try "" to get " inside your string
ie msgbox """fred""" will display "fred"
clear as mud!
Quote:
Originally posted by MadWorm
Chr$(34) will give you "
but try "" to get " inside your string
ie msgbox """fred""" will display "fred"
clear as mud!
Will result in an error.:rolleyes:Code:"""fred"""
It's because vb thinks that the string is ended after the 2nd ". And then there's just fred and that means nothing.
Try it!
works fine on my machine Win2k VB6 ent SP4Code:Private Sub Command1_Click()
MsgBox """fred"""
End Sub
I'm afraid you're wrong oetje. I do prefer xmin's method though. It just looks strange when you've got thousands of quotes in one string!
Here you go. Straight from MSDN.
Printing Quotation Marks in a String
Sometimes quotation marks (" ") appear in a string of text.
She said, "You deserve a treat!"
Because strings assigned to a variable or property are surrounded by quotation marks (" "), you must insert an additional set of quotation marks for each set to display in a string. Visual Basic interprets two quotation marks in a row as an embedded quotation mark.
For example, to create the preceding string, use the following code:
Text1.Text = "She said, ""You deserve a treat!"" "
To achieve the same effect, you can use the ASCII character (34) for a quotation mark:
Text1.Text = "She said, " & Chr(34) + "You deserve a treat!" & Chr(34)
Sorry, I was wrong.:(