O
O
Ord EO2020-11-29 20:45:25
ruby
Ord EO, 2020-11-29 20:45:25

How to capitalize every word except one?

There are addresses like ' BARRON WI 54812-9126', RICE LAKE WI 54868-9344';
How can I capitalize every word in such a string, but WIalways keep both letters capitalized?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-11-29
@OrdeO

str.gsub(/\b[A-Z]+\b/) {|m| m == 'WI' ? m : m.capitalize}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question