Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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

Report this thread to moderator Post Follow-up to this message
Old Post
Stlun
05-27-05 01:55 PM


Re: 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 = """"

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


Report this thread to moderator Post Follow-up to this message
Old Post
Rick Rothstein
05-27-05 01:55 PM


Re: Quotation mark as string
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



Report this thread to moderator Post Follow-up to this message
Old Post
Martin
05-27-05 01:55 PM


Re: 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 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/



Report this thread to moderator Post Follow-up to this message
Old Post
Mike D Sutton
05-27-05 01:55 PM


RE: Quotation mark as string
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 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




Report this thread to moderator Post Follow-up to this message
Old Post
Stlun
05-27-05 08:55 PM


RE: Quotation mark as string
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:
> 
>
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Charlie
05-27-05 08:55 PM


RE: Quotation mark as string
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:

> 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:
> 

Report this thread to moderator Post Follow-up to this message
Old Post
Stlun
05-27-05 08:55 PM


Re: Quotation mark as string
> > > 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


Report this thread to moderator Post Follow-up to this message
Old Post
Rick Rothstein
05-27-05 08:55 PM


Re: Quotation mark as string
"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.



Report this thread to moderator Post Follow-up to this message
Old Post
Jeff Johnson [MVP: VB]
05-27-05 08:55 PM


Re: Quotation mark as string

"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 !



Report this thread to moderator Post Follow-up to this message
Old Post
Stlun
05-28-05 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Visual Basic archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:19 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.