0

What's the difference between strings with single quotation marks and double quotation marks??

14th Jan 2018, 10:43 PM
james green
james green - avatar
4 Respostas
+ 11
Interpolation and escaping special characters are only available via double quoted strings. Ex (ruby): name = Kayla puts “My name is #{name}” => “My name is Kayla” The above variable interpolation won’t work with single quotes. puts ‘My name is #{name}’ =>’My name is #{Kayla}’ Also, the following: puts “I need to print a backspace at the end of this sentence\\” => “I need to print a backspace at the end of this sentence\” puts ‘I need to print a backspace at the end of this sentence\\’ => ‘I need to print a backspace at the end of this sentence\\’ * note how the backspace wasn’t escaped in the single quoted sentence. There are uses for both types of quotes, though. If you need to print a string that includes quotes, such as one that includes a famous person’s saying in quotes, you can keep the code cleaner looking by placing the quote in single quotes and the string in double quotes. You could also use the same type of quotes throughout the string, but only if you escape them (this applies only to double quoted strings).
15th Jan 2018, 4:21 AM
ScriptKittie
ScriptKittie - avatar
+ 3
Depends on the language. Could you specify the language as this affects the answer?
14th Jan 2018, 10:54 PM
non
+ 1
In most languages, single quotes and double quotes serve the exact same purpose, both declaring that something is a string/char. However, in some languages, such as C#, single quotes must only be used for declaring chars while double quotes must only be used for declaring strings, so it really depends on the language.
14th Jan 2018, 10:53 PM
Faisal
Faisal - avatar
0
Sorry.. To specify, I'm using Ruby
15th Jan 2018, 4:26 AM
james green
james green - avatar