O
O
Ord EO2020-10-24 00:13:16
ruby
Ord EO, 2020-10-24 00:13:16

How to reduce the first letter in certain words in a sentence?

There is a certain variable sentences that contains an expression where random words can be capitalized, how can you make the words Andand Ofchange the first letter in this variable to a small one, unless of course they are available.
Example

sentences = "The Department Of Higher Education And Workforce"
should become
"The Department of Higher Education and Workforce"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-10-24
@OrdeO

words = [ 'and', 'of' ]

sentences.gsub!(/\b(#{words.join('|')})\b/i) {|m| m.downcase}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question