Sign in to follow this  
Followers 0
stev379

Double quotes vs single quotes

10 posts in this topic

I've always used double quotes ("quote"), and doubling up on them when necessary.

Is there any functional reason why not use single quotes ('quote') instead?

I would thing that single quotes may process slightly faster in long scripts, but if there is a coding best practice or rule that argues for the use of double quotes, I would stick with them.

Thanks!

-Steve

Share this post


Link to post
Share on other sites



Strings are enclosed in double-quotes like "this". If you want a string to actually contain a double-quote use it twice like:

"here is a ""double-quote"" - ok?"

You can also use single-quotes like 'this' and 'here is a ' 'single-quote' ' - ok?'

You can mix quote types to make for easier working and to avoid having to double-up your quotes to get what you want. For example if you want to use a lot of double-quotes in your strings then you should use single-quotes for declaring them:

'This "sentence" contains "lots" of "double-quotes" does it not?'

is much simpler than:

"This ""sentence"" contains ""lots"" of ""double-quotes"" does it not?"

According to the help file, there seems to be no difference. I prefer single quote, most of the times. And I highly doubt they affect the script's speed, despite their length.

Share this post


Link to post
Share on other sites

Neither of them are faster than the other.

The reason for being able to use both is so you can put quotes in your strings

For instance, if I want a string to look like <double quote>some text<double quote>, then I could do this:

$string = '"some text"'

Share this post


Link to post
Share on other sites

Double quotes ARE in fact slower! I mean, I have to press the shift key just to insert one!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@weaponx :) lol

Edited by Hatcheda

Share this post


Link to post
Share on other sites

Double quotes ARE in fact slower! I mean, I have to press the shift key just to insert one!

LOL - yeah really, what a drag. :)

According to the help file, there seems to be no difference. I prefer single quote, most of the times. And I highly doubt they affect the script's speed, despite their length.

That does make sense, if I'm using a line of text that requires double quoting, it would be easier to read a few month later if I always stick with using one or the other.

Thanks for the info everybody.

'Thanks!'

Share this post


Link to post
Share on other sites

Sometimes you NEED to use both.

Anytime you are passing a command line paramater you must use double quotes inside single quotes.

i.e. Run('somefile.exe "C:\some folder with spaces\"')

Dos commands will flip out if you pass single quotes.

Also when I see people escaping double quotes instead of using single quotes it hurts my brain.

Straight from the help file:

EVIL!

"here is a ""double-quote"" - ok?"

NOT EVIL!

'here is a "double-quote" - ok?'

Share this post


Link to post
Share on other sites

Sometimes you NEED to use both.

Anytime you are passing a command line paramater you must use double quotes inside single quotes.

i.e. Run('somefile.exe "C:\some folder with spaces\"')

Dos commands will flip out if you pass single quotes.

Also when I see people escaping double quotes instead of using single quotes it hurts my brain.

Straight from the help file:

EVIL!

"here is a ""double-quote"" - ok?"

NOT EVIL!

'here is a "double-quote" - ok?'

WOW! No kidding. I hadn't thought about the cmd line situation. That's easliy half of what I do with scripts. Just to be sure I understand,... single quotes inside single quotes wouldn't work when sending a command?

Run('somefile.exe 'C:\some folder with spaces\'')

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Just refer to the Help File > Language Reference > Datatypes

Dos commands don't like any form of single quotes. You can nest single quotes within single quotes if you escape the ones inside.

Edited by weaponx

Share this post


Link to post
Share on other sites

use single quotes if you need to have double quotes in the string:

'some text "double quotes"'

use double quotes if you need to have single quotes in the string:

"some text 'single quotes'"

If you need to use both:

"some text 'single quotes' some more text " & '"double quotes" some more text'

this would equal:

some text 'single quotes' some more text "double quotes" some more text

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0