irb(main):011:0> " gk".gsub("\s",“h”)
=> “hhhhhgk”
irb(main):012:0> " gk".gsub("\s+",“h”)
=> " gk"
how can i make " gk" into “hgk”?
i get it
it is " gk".gsub(/\s+/,“h”),not " gk".gsub("\s+",“h”)
On Sun, Aug 29, 2010 at 6:11 PM, Pen T. [email protected] wrote:
irb(main):011:0> " gk".gsub(“\s”,“h”)
=> “hhhhhgk”
irb(main):012:0> " gk".gsub(“\s+”,“h”)
=> " gk"
how can i make " gk" into “hgk”?
" gk".gsub(/\s+/,“h”)
=> “hgk”
On Sun, Aug 29, 2010 at 8:11 PM, Pen T. [email protected] wrote:
irb(main):011:0> " gk".gsub(“\s”,“h”)
=> “hhhhhgk”
irb(main):012:0> " gk".gsub(“\s+”,“h”)
=> " gk"
how can i make " gk" into “hgk”?Posted via http://www.ruby-forum.com/.
Your second example is almost there, except that it is a String, not a
Regexp. Regexp are enclosed with slashes rather than quotes (Regexp has
it’s
own literal, as opposed to languages like Java, where it needs to be
defined
within a String)
" gk".gsub( /\s+/ , “h”) # => “hhghkh”