[ruby-core:71037] Re: Bug? Trying to get backslashes into a string using sub or gsub

From: Gavin Sinclair <gsinclair@...>
Date: 2015-10-10 00:04:34 UTC
List: ruby-core #71037
Replying to my own question, I found this:

http://stackoverflow.com/questions/1542214/weird-backslash-substitution-in-ruby

I now understand, so please ignore my bug question.

On Sat, Oct 10, 2015 at 10:37 AM, Gavin Sinclair <gsinclair@gmail.com>
wrote:

> I'm trying to emit two backslashes in a string (for a newline in LaTeX)
> and it's proving very difficult.
>
> Is the behaviour shown below a bug?
>
> irb(main):054:0> '\\\\'.bytes == [92,92]
> => true
> irb(main):056:0> "NL".sub('NL', '\\\\').bytes == [92,92]
> => false
>
> Thanks,
> Gavin
>

In This Thread

Prev Next