| Author |
Quotation mark as string
|
|
|
| I want to declare a string with just one quotation mark, how can it be done?
Ex.
Dim strQuotationMark As String
strQuotationMark = """
If I try to declare like above VB just fills up with one more quotation mark?!
results
Dim strQuotationMark As String
strQuotationMark = """"
/Stlun
| |
| Rick Rothstein 2005-05-27, 8:55 am |
| > I want to declare a string with just one quotation mark, how can it be
done?
> Ex.
> Dim strQuotationMark As String
> strQuotationMark = """
>
> If I try to declare like above VB just fills up with one more
quotation mark?!
> results
> Dim strQuotationMark As String
> strQuotationMark = """"
Inside of the quote marks required to delineate a text string, you would
use two adjacent quote marks to signal to VB you want one included
inside of the string.
strQuotationMark = """"
You can do this directly inside the string and dispense with the
strQuotationMark variable. Where you would have something like this
txtTextVariable = "Quote mark " & strQuotationMark & " symbol"
you could do it directly like this
txtTextVariable = "Quote mark "" symbol"
Another possibility, if you want to stay with the variable, is to use
Chr$(34) instead of the doubled up quote marks
strQuotationMark = Chr$(34)
Rick - MVP
| |
| Martin 2005-05-27, 8:55 am |
| You can use
Dim strQuotationMark As String
strQuotationMark = chr(34)
instead your code.
Also your code will work
Dim strQuotationMark As String
strQuotationMark = """"
"Stlun" <stlun@DELETE.THIS.hotmail.com> wrote in message
news:E6C641F7-4C0D-44D2-BD3C-11619299537B@microsoft.com...
> I want to declare a string with just one quotation mark, how can it be
done?
> Ex.
> Dim strQuotationMark As String
> strQuotationMark = """
>
> If I try to declare like above VB just fills up with one more quotation
mark?!
> results
> Dim strQuotationMark As String
> strQuotationMark = """"
>
> /Stlun
| |
| Mike D Sutton 2005-05-27, 8:55 am |
| > I want to declare a string with just one quotation mark, how can it be done?
> Ex.
> Dim strQuotationMark As String
> strQuotationMark = """
>
> If I try to declare like above VB just fills up with one more quotation mark?!
> results
> Dim strQuotationMark As String
> strQuotationMark = """"
In addition to the other replies, the double quotation mark is known as an escape sequence; basically as soon as the VB
code parser hits a quotation mark is assumes that it's either at the start or end of a string, however if it's
immediately followed by another quotation mark it overrides that assumption and interprets it as a single quotation mark
instead. The reason for the 4 quotation marks is that all string literals must start and end with a quotation mark (VB
will append the trailing one if you omit it which is what's happening when you enter three quotes), and the middle two
are the quote escape sequence. You can see this with this simple test:
'***
Debug.Print Len("""") ' Prints 1
'***
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/
| |
|
| Thanx for a fast reply, I'll go for the simple solution and use
strQuotationMark = chr(34)
/Stlun
"Stlun" wrote:
> I want to declare a string with just one quotation mark, how can it be done?
> Ex.
> Dim strQuotationMark As String
> strQuotationMark = """
>
> If I try to declare like above VB just fills up with one more quotation mark?!
> results
> Dim strQuotationMark As String
> strQuotationMark = """"
>
> /Stlun
| |
| Charlie 2005-05-27, 3:55 pm |
| Debug.Print "Once you get ""accustomed to"" using the"
Debug.Print """doubled-up"" quote marks in a ""quoted"
Debug.Print "string,"" you'll realize which one is really"
Debug.Print "the " & strQuotationMark & "simpler" & strQuotationMark & "
method"
"Stlun" wrote:
> Thanx for a fast reply, I'll go for the simple solution and use
> strQuotationMark = chr(34)
>
> /Stlun
>
> "Stlun" wrote:
>
>
>
>
| |
|
| When you put this way I must agree to that it seems to be a better way to do
it.
I just must practice more to get the "right" thinking... ;-)
"Charlie" wrote:
[color=darkred]
> Debug.Print "Once you get ""accustomed to"" using the"
> Debug.Print """doubled-up"" quote marks in a ""quoted"
> Debug.Print "string,"" you'll realize which one is really"
> Debug.Print "the " & strQuotationMark & "simpler" & strQuotationMark & "
> method"
>
>
> "Stlun" wrote:
>
| |
| Rick Rothstein 2005-05-27, 3:55 pm |
| > > > Thanx for a fast reply, I'll go for the simple solution and use
>
> When you put this way I must agree to that it seems to be a better way
to do
> it.
> I just must practice more to get the "right" thinking... ;-)
Perhaps this previous posting of mine will help you get comfortable with
seeing how the internal double quotes are used internally, at the ends
of strings and all by themselves...
In VB, all string constants (where you provide the text directly) are
surrounded by double-quotes. Within these double quotes, you include a
single double-quote by placing two double-quotes next to each other.
Consider this:
Print "Quote "" Mark" which outputs ==> Quote " Mark
Remove the word Mark and the blank space in front of it to get the
following
Print "Quote """ which outputs ==> Quote "
Now remove the word Quote and the blank space after it to get the
following
Print """" which outputs ==> "
Rick - MVP
| |
| Jeff Johnson [MVP: VB] 2005-05-27, 3:55 pm |
|
"Charlie" <Charlie@discussions.microsoft.com> wrote in message
news:E7D29B4B-69A4-48C7-9AEB-95E9943B07CD@microsoft.com...
> Debug.Print "Once you get ""accustomed to"" using the"
> Debug.Print """doubled-up"" quote marks in a ""quoted"
> Debug.Print "string,"" you'll realize which one is really"
> Debug.Print "the " & strQuotationMark & "simpler" & strQuotationMark & "
> method"
Oooohhhh. I really like that example. Consider it stolen.
| |
|
|
"Rick Rothstein" wrote:
> to do
>
> Perhaps this previous posting of mine will help you get comfortable with
> seeing how the internal double quotes are used internally, at the ends
> of strings and all by themselves...
>
> In VB, all string constants (where you provide the text directly) are
> surrounded by double-quotes. Within these double quotes, you include a
> single double-quote by placing two double-quotes next to each other.
> Consider this:
>
> Print "Quote "" Mark" which outputs ==> Quote " Mark
>
> Remove the word Mark and the blank space in front of it to get the
> following
>
> Print "Quote """ which outputs ==> Quote "
>
> Now remove the word Quote and the blank space after it to get the
> following
>
> Print """" which outputs ==> "
>
> Rick - MVP
>
>
Hmmm I see this make it ever more clear, this IS the way to code !
|
|
|
|