I have a data file of names and address...all of them are upper case.
How can I convert it to properly make the first letter upper case, and the rest lower case (except for states, for example)?
I could probably isolate the states to not go through the parse, but for the rest, how could I do this for a ruby on rails application?
Ruby has a few methods for changing the case of strings. To convert to lowercase, use downcase : "hello James!". downcase #=> "hello james!"
Ruby | String capitalize() Method capitalize is a String class method in Ruby which is used to return a copy of the given string by converting its first character uppercase and the remaining to lowercase.
If you can separate the states out, like you say, it's easy:
my_address_string.titlecase
It'll capitalize the first letter of every word (including some I'd rather it didn't, like "a" or "the", but hey...) and uncapitalize the rest. Sounds just like what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With