Hi, In my application I want to find out the occurance of substring "http:\\" in the main string "http:\\www.abc.com" Here how to find out whether substring "http:\\" is present in my String? & if substring "http:\\" is present then I want to delete it from main string. How to do this? PLs help me. Thanx in advance. Prash -- Posted via http://www.ruby-forum.com/.
On 6/8/06, Prashant Tiwari <tiwari_p_k@yahoo.com> wrote:> Hi, > > In my application I want to find out the occurance of substring > "http:\\" in the main string "http:\\www.abc.com" > > Here how to find out whether substring "http:\\" is present in my > String? >s = "http:\\www.abc.com" regexp = %r{http:\\} s =~ regexp> & if substring "http:\\" is present then I want to delete it from main > string. > How to do this?s.gsub(regexp, '''')> > PLs help me. > > Thanx in advance. > Prash > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -Alder
Prashant Tiwari
2006-Jun-08 07:05 UTC
[Rails] Re: How to find particular pattern in string?
Hi alder, Thanx for ur reply. I tried with your suggestion. But it works only when there is blank space between "http:\\" & rest of string in my Main String. ie, it is working only when my mainstring is like :- "http:\\ www.abc.com" (note blank space betn "http:\\" and "www.abc.com" ) & when my string is like "http:\\www.abc.com" (without balnk space) its not working. Can you please again tell me with modifying your above solution for my mainstring without blank space? Please help me. Thanx again pras Alder Green wrote:> On 6/8/06, Prashant Tiwari <tiwari_p_k@yahoo.com> wrote: >> Hi, >> >> In my application I want to find out the occurance of substring >> "http:\\" in the main string "http:\\www.abc.com" >> >> Here how to find out whether substring "http:\\" is present in my >> String? >> > > s = "http:\\www.abc.com" > regexp = %r{http:\\} > s =~ regexp > >> & if substring "http:\\" is present then I want to delete it from main >> string. >> How to do this? > > s.gsub(regexp, '''')-- Posted via http://www.ruby-forum.com/.
On 6/8/06, Prashant Tiwari <tiwari_p_k@yahoo.com> wrote:> Hi alder, > Thanx for ur reply. > I tried with your suggestion. But it works only when there is blank > space between "http:\\" & rest of string in my Main String. > ie, it is working only when my mainstring is like :- > "http:\\ www.abc.com" (note blank space betn "http:\\" and > "www.abc.com" ) > & when my string is like "http:\\www.abc.com" (without balnk space) its > not working. > Can you please again tell me with modifying your above solution for my > mainstring without blank space?The above solution should and does work, regardless of the character following the substring. I tested it with the strings you provided, and it did work. Check if you made an error trying it, perhaps using %r{http:\\ } for the regexp.> > Please help me. > Thanx again > pras > > > Alder Green wrote: > > On 6/8/06, Prashant Tiwari <tiwari_p_k@yahoo.com> wrote: > >> Hi, > >> > >> In my application I want to find out the occurance of substring > >> "http:\\" in the main string "http:\\www.abc.com" > >> > >> Here how to find out whether substring "http:\\" is present in my > >> String? > >> > > > > s = "http:\\www.abc.com" > > regexp = %r{http:\\} > > s =~ regexp > > > >> & if substring "http:\\" is present then I want to delete it from main > >> string. > >> How to do this? > > > > s.gsub(regexp, '''') > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -Alder
>>>>> "Prashant" == Prashant Tiwari <tiwari_p_k@yahoo.com> writes:> Hi, > In my application I want to find out the occurance of substring > "http:\\" in the main string "http:\\www.abc.com"Methods for that live in the aptly named Ruby class String. In this case, it sounds like you want the method String#index. -- Calle Dybedahl <calle@cyberpomo.com> http://www.livejournal.com/users/cdybedahl/ "It''s not much of a silver lining, but I''ll take what I can get." -- yasminm, on LiveJournal
Calle Dybedahl <rails@...> writes:> > >>>>> "Prashant" == Prashant Tiwari <tiwari_p_k@...> writes: > > > Hi, > > In my application I want to find out the occurance of substring > > "http:\\" in the main string "http:\\www.abc.com" > > Methods for that live in the aptly named Ruby class String. In this > case, it sounds like you want the method String#index.s=''http://www.abc.com'' pat=''http://'' n=s.index(pat) if n!=nil s.sub!(pat, '''') end This is simpler than regex.