Afficher un message
Vieux 20/11/2007, 19h24   #2
Phrogz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: gsub question on special charaters

On Nov 20, 11:18 am, Robert Keller <rlkel...@yahoo.com> wrote:
> I have a string that looks like this :
>
> ts = "^LThe beginning of the sentence"
>
> I want to remove the "^L"
>
> I've tried
>
> ts.gsub!(/^[\^L]/,'')
>
> which removes the "^", but I need to remove the "^L" when they are
> together and at the beginning of the sentence.


irb(main):001:0> ts = "^LThe beginning of the sentence"
=> "^LThe beginning of the sentence"
irb(main):002:0> ts.sub /^\^L/, ''
=> "The beginning of the sentence"

Also:
1) Do you really mean ^ (start of line) or do you mean \A (start of
string)?
2) No need to use gsub if there's only ever going to be a single
match.
  Réponse avec citation
 
Page generated in 0,05022 seconds with 9 queries