I know the backslash escapes a character, so in the first line, I escape
the quote so it will return a string that is a single quote, but in the
second one I would expect it to return "\", instead it returns "\\" both
backslashes, and I only want one of them. My actual problem looks like
this:
In Ruby, there is a distinction between strings that are between double quotes and strings in single quotes.
"\\" escapes the necessary characters, and also allows substitution. ex: "#{name}" => "Pradeep"
'\\' does not do any of these. ex: '#{name}' => '#{name}'
Single-quoted strings are faster than double-quoted strings.
- Pradeep
···
On Nov 6, 2007, at 8:00 PM, Jeremy Woertink wrote:
I know the backslash escapes a character, so in the first line, I escape
the quote so it will return a string that is a single quote, but in the
second one I would expect it to return "\", instead it returns "\\" both
backslashes, and I only want one of them. My actual problem looks like
this:
I know the backslash escapes a character, so in the first line, I escape
the quote so it will return a string that is a single quote, but in the
second one I would expect it to return "\", instead it returns "\\" both
backslashes, and I only want one of them. My actual problem looks like
this:
I know the backslash escapes a character, so in the first line, I escape
the quote so it will return a string that is a single quote, but in the
second one I would expect it to return "\", instead it returns "\\" both
backslashes, and I only want one of them. My actual problem looks like
this:
I know it seems like that should be the case, but can you provide any
proof that it is? In all the tests I've done, I've never found single-
quoted strings to be any bit measurably faster than double-quoted.
···
On Nov 6, 6:28 pm, Pradeep Elankumaran <skyfallsin...@gmail.com> wrote:
In Ruby, there is a distinction between strings that are between
double quotes and strings in single quotes.
"\\" escapes the necessary characters, and also allows substitution.
ex: "#{name}" => "Pradeep"
'\\' does not do any of these. ex: '#{name}' => '#{name}'
Single-quoted strings are faster than double-quoted strings.
Right. When irb shows you "\\", what it's showing you is the
double-quoted correct representation of a single backslash.
Todd
···
On 11/6/07, Jeremy Woertink <jeremywoertink@gmail.com> wrote:
yermej wrote:
> On Nov 6, 7:00 pm, Jeremy Woertink <jeremywoert...@gmail.com> wrote:
>> second one I would expect it to return "\", instead it returns "\\" both
>> the string that is returned is still wrong.
>>
>> ~Jeremy
>> --
>> Posted viahttp://www.ruby-forum.com/.
>
> If you actually output the string:
>
>> puts '\\'
> \
> => nil
>
> you should get the result you're expecting.
Rock on.
So basically I had to do \\\\ just to get \\ and \\ just to get \.
Crazy, but it works so I'm happy.
Thanks