Converting upper-case string into title-case using Ruby

后端 未结 10 1385
小鲜肉
小鲜肉 2020-12-25 10:46

I\'m trying to convert an all-uppercase string in Ruby into a lower case one, but with each word\'s first character being upper case. Example:

convert \"MY STRING HE

10条回答
  •  庸人自扰
    2020-12-25 11:25

    If you're using Rails (really all you need is ActiveSupport, which is part of Rails), you can use titleize:

    "MY STRING HERE".titleize
    # => "My String Here"
    

提交回复
热议问题