stev379 Posted December 7, 2007 Posted December 7, 2007 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
Nahuel Posted December 7, 2007 Posted December 7, 2007 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.
DW1 Posted December 7, 2007 Posted December 7, 2007 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"' AutoIt3 Online Help
weaponx Posted December 7, 2007 Posted December 7, 2007 Double quotes ARE in fact slower! I mean, I have to press the shift key just to insert one!
John117 Posted December 7, 2007 Posted December 7, 2007 (edited) @weaponx lol Edited December 7, 2007 by Hatcheda
stev379 Posted December 7, 2007 Author Posted December 7, 2007 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!'
weaponx Posted December 7, 2007 Posted December 7, 2007 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?'
stev379 Posted December 7, 2007 Author Posted December 7, 2007 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\'')
weaponx Posted December 7, 2007 Posted December 7, 2007 (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 December 7, 2007 by weaponx
DW1 Posted December 7, 2007 Posted December 7, 2007 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 AutoIt3 Online Help
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now