0
What's the difference between strings with single quotation marks and double quotation marks??
4 RĂ©ponses
+ 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).
+ 3
Depends on the language. Could you specify the language as this affects the answer?
+ 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.
0
Sorry.. To specify, I'm using Ruby