Forum: Ruby on Rails GSUB

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2c8973317fdf972875963b3927f1d587?d=identicon&s=25 m. jk (mjayakumar2k6)
on 2008-12-24 12:49
hi ,

 I have a string with "\". how can i gsub the string?

i tried

"\".gsub('\','')


but it is giving error.

thanks in advance
JK
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-12-24 12:57
(Received via mailing list)
On Dec 24, 11:49 am, Jayakumar Manickam <rails-mailing-l...@andreas-
s.net> wrote:
> hi ,
>
>  I have a string with "\". how can i gsub the string?
>
> i tried
>
> "\".gsub('\','')
>
> but it is giving error.
>
Neither of those string literals because the \ escapes the close quote
mark. You need to escape literal backslashes.

Fred
2c8973317fdf972875963b3927f1d587?d=identicon&s=25 m. jk (mjayakumar2k6)
on 2008-12-25 07:20
Frederick Cheung wrote:
> On Dec 24, 11:49�am, Jayakumar Manickam <rails-mailing-l...@andreas-
> s.net> wrote:
>> hi ,
>>
>> �I have a string with "\". how can i gsub the string?
>>
>> i tried
>>
>> "\".gsub('\','')
>>
>> but it is giving error.
>>
> Neither of those string literals because the \ escapes the close quote
> mark. You need to escape literal backslashes.
>
> Fred

i tried  "\\".gsub('\\',''). it is working fine.


thanks
This topic is locked and can not be replied to.