From case to case to proposal

I am trying to write an assistant to translate a line from "something_like_this" to "Something like this" . I use "something_like_this".titlecase to get it before "Something like this" , but I am stuck in the lower case of every uppercase letter except the first one.

I assume I'm looking for something like this:

 def write_sentence string.titlecase.gsub!(/UPPERCASE-TO-LOWERCASE-EXCEPT-FIRST/) #that should be something to lowercase everything except the first letter return string end 

So, in the view, I could just write string.write_sentence and return it exactly what I want. Any thoughts?

Thanks!

EDIT

I should mention that a string can sometimes be just one word, in which case the string must be converted from "something" to "something" .

+7
source share
2 answers
+24
source

The simplest solution would probably be to just grab the first letter, smooth it, and then put together with a new line where the first letter has already been deleted. Then just run normal replacement to change _ to . No fancy regular expression needed.

0
source

All Articles