I only want to capitalize the first char and leave the others as is.
For example:
"fooBar".titleize returns "Foo Bar". Should return FooBar.
"foo_Bar".capitalize returns "Foo_bar" Should return Foo_Bar.
Any way I can do this?
irb(main):001:0> s = "foo_Bar"
=> "foo_Bar"
irb(main):002:0> s[0] = s[0].upcase
=> "F"
irb(main):003:0> s
=> "Foo_Bar"
Or with regex for in-place substitution:
irb(main):001:0> s = "foo_Bar"
=> "foo_Bar"
irb(main):002:0> s.sub!(/^\w/) {|x| x.upcase}
=> "Foo_Bar"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With