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 – 2015-05-10T23:42:57.910
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 – 2015-05-11T00:48:39.247
2Dennis, please preserve spaces from the input... – WallyWest – 2015-05-11T01:04:28.137
3!= TitleCase dam it! c# loses AGAIN! – Ewan – 2015-05-11T11:07:38.440
@WallyWest I don't think there should be a
at the end of the example output? Also a double space
before Pigeon-toed`? – Tim – 2015-05-11T16:19:15.0031@Tim The double space before Pigeon-toed is correct. He said to preserve spacing. – mbomb007 – 2015-05-11T17:04:19.440
2What separates the words? Any whitespace (tabs, newlines, etc) or just spaces? – Steven Rumbalski – 2015-05-11T18:22:45.797
1Is this ASCII only or should the answer handle unicode? – Bakuriu – 2015-05-12T09:31:07.527
@StevenRumbalski just standard space (ASCII 32) – WallyWest – 2015-05-12T14:55:22.063
@Bakuriu At this point it's just standard ASCII... – WallyWest – 2015-05-12T14:55:57.943
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 – 2015-05-13T08:39:41.4271@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 – 2015-05-14T13:55:11.110
1
Not even an honorable mention for the 13-byte Perl solution?
– ThisSuitIsBlackNot – 2015-05-27T22:22:22.443Honorable mention made! Nice work! – WallyWest – 2015-05-27T22:40:29.797