34
6
This is a relatively quick one, but I'm sure you'll like it.
Codegolf a program that will take input in the form of a sentence and then provide the output with the first letter capitalized in each word.
Rules:
Submissions may not be in the form of a function. So no:
function x(y){z=some_kind_of_magic(y);return z;}
as your final answer... Your code must show that it takes input, and provides output.The code must preserve any other capital letters the input has. So
eCommerce and eBusiness are cool, don't you agree, Richard III?
will be rendered as
ECommerce And EBusiness Are Cool, Don't You Agree, Richard III?
Some of you may be thinking, "Easy, I'll just use regex!" and so using the native regex in your chosen golfing language will incur a 30 character penalty which will be applied to your final code count. Evil laugh
A "word" in this case is anything separated by a space. Therefore
palate cleanser
is two words, whereaspigeon-toed
is considered one word.if_you_love_her_then_you_should_put_a_ring_on_it
is considered one word. If a word starts with a non-alphabetical character, the word is preserved, so_this
after rendering remains as_this
. (Kudos to Martin Buttner for pointing this test case out).- 4b. There is no guarantee that words in the input phrase will be separated by a single space.
Test Case, (please use to test your code):
Input:
eCommerce rocks. crazyCamelCase stuff. _those pigeon-toed shennanigans. Fiery trailblazing 345 thirty-two Roger. The quick brown fox jumped over the lazy dogs. Clancy Brown would have been cool as Lex Luthor. good_bye
Output:
ECommerce Rocks. CrazyCamelCase Stuff. _those Pigeon-toed Shennanigans. Fiery Trailblazing 345 Thirty-two Roger. The Quick Brown Fox Jumped Over The Lazy Dogs. Clancy Brown Would Have Been Cool As Lex Luthor. Good_bye
This is code golf, shortest code wins...
Good luck...
Oh crap, I was thinking of multiple spaces but forgot to mention it... I've updated the brief accordingly... The brief will be locked from this point forward. – WallyWest – 10 years ago
1What about spaces at the end of the line? Do we have to preserve them? Can we add one if it serves our needs? – Dennis – 10 years ago
2Dennis, please preserve spaces from the input... – WallyWest – 10 years ago
3!= TitleCase dam it! c# loses AGAIN! – Ewan – 10 years ago
@WallyWest I don't think there should be a
at the end of the example output? Also a double space
before Pigeon-toed`? – Tim – 10 years ago1@Tim The double space before Pigeon-toed is correct. He said to preserve spacing. – mbomb007 – 10 years ago
2What separates the words? Any whitespace (tabs, newlines, etc) or just spaces? – Steven Rumbalski – 10 years ago
1Is this ASCII only or should the answer handle unicode? – Bakuriu – 10 years ago
@StevenRumbalski just standard space (ASCII 32) – WallyWest – 10 years ago
@Bakuriu At this point it's just standard ASCII... – WallyWest – 10 years ago
Does ”Ascii only” mean that answers that correctly capitalize e.g. ä to Ä are incorrent? Such as this one: http://codegolf.stackexchange.com/questions/49950/capitalize-first-letter-of-each-word-of-input#answer-49956
– leo – 10 years ago1@leo: Reading the OP's comment in context, it says the code doesn't have to handle non-ASCII characters. I'd say that means behavior for non-ASCII letters is undefined. – Dennis – 10 years ago
1
Not even an honorable mention for the 13-byte Perl solution?
– ThisSuitIsBlackNot – 10 years agoHonorable mention made! Nice work! – WallyWest – 10 years ago