Convert a string to sentence case

05AB1E, 3 bytes


Try it online!

Nothing like a good old built-in answer! This converts the string to lowercase and then performs sentence case.

Erlang (escript), 77 bytes

If non-periods are allowed... well, that greatly golfs my program!

g(H)->[string:titlecase(string:lowercase(I))||I<-re:split(H,"(\\W[\\W ]+)")].

Try it online!


g(H)->                      % Define a function.

re:split(H,"(\\W[\\W ]+)")  % Split the operand on "sentences", keeping the items reserved for splitting.

                            % I.e. none of the items from the string is missing after the split

||I<-   ]                   % For every item in a sentence,

                            %     Title case the sentence.
.                           % End the function.                            

JavaScript (Node.js), 101 bytes

s=>(s.reduce((a,c)=>c=='.'?(r+=c,'Upp'):c>' '?(r+=c['to'+a+'erCase'](),'Low'):(r+=c,a),'Upp',r=''),r)

Try it online!