# Convert the first letter of each word to uppercase, and the rest to lowercase [closed]

## Description

Your task is to take a string as input, and convert the first letter of each word to uppercase, and the rest to lowercase.

## Test Cases

Input => Output

ISN'T THIS A REALLY COOL TEST CASE??? => Isn't This A Really Cool Test Case???
tHis iS A rEALLY WeiRd SeNTEncE => This Is A Really Weird Sentence
I Like This Sentence => I Like This Sentence

### Edit: no built-ins allowed.

This is , so lowest byte count wins. Good luck!

• Since at least one current answer uses built-ins, I'd like to ever so subtly drop this link here in the comments. – Geobits Jun 20 '16 at 5:35
• What counts as a built-in? – Leaky Nun Jun 20 '16 at 5:38
• How do you define a word? – Dennis Jun 20 '16 at 6:00
• Possible duplicate of Capitalize first letter of each word of input – Kevin Cruijssen Jun 20 '16 at 6:48
• @Geobits I disagree. When there's only a few answers yet, improving the challenge is more important than avoiding the invalidation of a few answers. Of course when a rule change would require rewriting 20 answers, then it's probably not worth it, but this early on, I'm definitely n favour of the change. Nevertheless, MCMastery, I'd recommend using the sandbox next time where details like this can be ironed out before you risk invalidating answers. – Martin Ender Jun 20 '16 at 7:03

# V, 14 8 bytes

gu$ògUlW  Try it online! Explanation: gu$       #Make everything lowercase
ò      #Recursively
gUl   #Make the current character uppercase
W  #And move forward a word


Here is a 9-byte, non-competing version (the old interpreter had a bug):

gu$Ó¼÷/Õ°  This version is just a regex: gu$            #Make everything lowercase
Ó¼÷/Õ°      #Expands into ':s/\<\w/\U\0/g

• Use a heart to mark the unprintable – Leaky Nun Jun 20 '16 at 5:29
• I thought this would be like vim but the ós are scaring me :| – Downgoat Jun 20 '16 at 5:39

# s-lang, 7 bytes (Non-competing)

### Try it here!

w[ ]Cc!


## Explanation:

• w[ ] splits the input string by spaces
• C converts the selection (which is now the split-up words) to lower-case
• c! c converts the selection to upper-case, but since it uses the parameter !, it only converts the first letter of each range of characters in the selection (which are words since we split by spaces)
• The regex feature of this language is cool +1 – Downgoat Jun 20 '16 at 5:45
• @Upgoat thanks! – MCMastery Jun 20 '16 at 5:55

# Pyth, 6 bytes

jdm+rhd1rtd0c
jdrR4c


Test suite.

Split into words, capitalize each, then join by space.

It is not a built-in, because capitalize converts test case into Test case instead of Test Case.

### (with built-ins)

r5


Test suite.

• No built-ins are allowed so make the second one your top answer – Downgoat Jun 20 '16 at 5:36
• @Upgoat See, this is why you don't change rules after answers have been posted. – Geobits Jun 20 '16 at 5:37
• @Geobits idk it's just "no built-ins". It's not a radical rule change like other challenges have had – Downgoat Jun 20 '16 at 5:38
• BTW, you can do 10 bytes even without r4. <space>uprHqGdQd – PurkkaKoodari Jun 20 '16 at 7:38

# Ruby, 29 bytes

gets.gsub(/\S+/,&:capitalize)


I'm still learning ruby though >_>

## Pyke, 5 bytes

cml5J


Try it here!

Split, map caps, join

• Why does Pyke not default join by newlines :o – Leaky Nun Jun 20 '16 at 6:44
• Because by default Pyke outputs the stack on multiple lines, 1 per element. It means I often don't need to join at all – Blue Jun 20 '16 at 7:35

# Retina, 19 bytes

TLl
TlL(^|\s).


Try it online!

• T01lL\S+ – Martin Ender Jun 20 '16 at 9:18

# Python, 51 bytes

3 bytes thanks to xnor.

lambda n:' '.join(a.capitalize()for a in n.split())
lambda n:' '.join(map(str.capitalize,n.split()))


Ideone it!

### using built-in, 28 bytes

from string import*
capwords


Ideone it!

• I don't think this answer is valid without actually calling anything, or taking input. (unless I missed a meta post) – James Jun 20 '16 at 5:30
• It is a function, just like the ones in my challenge of binary logic gates – Leaky Nun Jun 20 '16 at 5:32
• You can map the function str.capitalize in place of the list comp. Also, str.title seems to work. – xnor Jun 20 '16 at 6:06
• @xnor str.title would convert Isn't into Isn'T. – Dennis Jun 20 '16 at 6:10
• I didn't suggest map`. xnor did. – Dennis Jun 20 '16 at 6:50