我有一个字符串
s = "Test TEst TEST. Test. TEST. TEST. Test test test."
我需要使结果像这样
s = "Test test test. Test. Test. Test. Test test test."
我如何在ruby上做到这一点?
THX。
答案 0 :(得分:3)
s = "Test TEst TEST. Test. TEST. TEST. Test test test."
p s.split('. ').map(&:capitalize).join('. ')
#=> "Test test test. Test. Test. Test. Test test test."
答案 1 :(得分:2)
s.gsub(/\w[^.]*/, &:capitalize)
# => "Test test test. Test. Test. Test. Test test test."