EamonnMcElroy
EamonnMcElroy

Reputation: 607

Capitalise every character after certain character

I have a string eg. String-aa. I want to be able to capitalise every letter after the "-". Is there a straightforward was of achieving this?

I am aware of .capitalize however dont know how to implement for this particular requirement.

Upvotes: 0

Views: 23

Answers (1)

Deepak Mahakale
Deepak Mahakale

Reputation: 23711

You can make use of block form of gsub

"String-aa-bbbb".gsub(/-\w+/){|e| e.upcase}
#=> "String-AA-BBBB"

The above code will capture a letter followed by - and will capitalize it

Upvotes: 1

Related Questions