-1

我有一个字符串

s = "Test TEst TEST. Test. TEST. TEST. Test test test."

我需要使结果像这样

s = "Test test test. Test. Test. Test. Test test test."

我怎么能在 ruby​​ 上做到这一点?

谢谢。

4

2 回答 2

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."
于 2013-11-15T10:01:07.660 回答
2
s.gsub(/\w[^.]*/, &:capitalize)
# => "Test test test. Test. Test. Test. Test test test."
于 2013-11-15T10:09:10.660 回答