Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this message> 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
Post Follow-up to this messageYou 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
Post Follow-up to this message> 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 ma
rk?!
> results
> Dim strQuotationMark As String
> strQuotationMark = """"
In addition to the other replies, the double quotation mark is known as an e
scape sequence; basically as soon as the VB
code parser hits a quotation mark is assumes that it's either at the start o
r 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 m
ust start and end with a quotation mark (VB
will append the trailing one if you omit it which is what's happening when y
ou 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/
Post Follow-up to this messageThanx 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 don e? > Ex. > Dim strQuotationMark As String > strQuotationMark = """ > > If I try to declare like above VB just fills up with one more quotation ma rk?! > results > Dim strQuotationMark As String > strQuotationMark = """" > > /Stlun
Post Follow-up to this messageDebug.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: > > > >
Post Follow-up to this messageWhen 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: > 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: >
Post Follow-up to this message> > > 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
Post Follow-up to this message"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.
Post Follow-up to this message"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 !
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.