The " character is used to start or end a string, so the following fails:
This is because VB thinks that you want the string to end before the word right.Code:Dim myString as String myString = "I want a quote in my string " right there!"
To put the quote character into a string you need to use one of the following methods:
Method 1: Use twice as many quote characters as you want, eg:
Method 2: Use a constant to represent the quote character, and add that to your string. This method is probably the easiest to read:Code:Dim myString as String myString = "I want a quote in my string "" right there!"
Note that the "Const ... " line can be placed in the General Declarations section of a form/module for use throughout.Code:Const QUOTE = """" Dim myString as String myString = "I want a quote in my string " & QUOTE & " right there!"
Method 3: Use the Chr function (which returns the character denoted by the ascii code you provide) with the ascii code of the " character (which is 34), eg:
Note that as this method involves a function it is slower than methods 1 and 2, especially in loops etc.Code:Dim myString as String ' Chr(34) is the same as the " character myString = "I want a quote in my string " & Chr(34) & " right there!"


Reply With Quote