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.
m. j. (Guest)
on 2008-12-24 13: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
Frederick C. (Guest)
on 2008-12-24 13: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
m. j. (Guest)
on 2008-12-25 08:20
Frederick C. 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.