Actually, WordBoundary
won't always work correctly (see this thread):
str = "the lazy dog jumped over the quick brown fox.";
strAcc = "árv ízt űr őt ük örf úr óg ép";
StringReplace[str, WordBoundary ~~ x_ :> ToUpperCase[x]]
StringReplace[strAcc, WordBoundary ~~ x_ :> ToUpperCase[x]]
"The Lazy Dog Jumped Over The Quick Brown Fox."
"Árv Ízt űR őT Ük Örf Úr Óg Ép" (* note ű,ő instead of Ű,Ő *)
Use instead this custom made toTitleCase
:
toTitleCase[str__] := StringJoin@Riffle[ToUpperCase@StringTake[#, 1] <>
ToLowerCase@StringTake[#, {2, -1}] & /@ StringSplit@StringJoin@str, " "];
toTitleCase[str]
toTitleCase[strAcc]
"The Lazy Dog Jumped On The Quick Brown Fox."
"Árv Ízt Űr Őt Ük Örf Úr Óg Ép"
In version 10.1, this is built in as ToTitleCase
(if I recall correctly, it was an experimental function; documentation is no longer accessible on the net). This version removes all non-alphanumeric characters from the string; I assume this is a bug.
ToTitleCase[str]
ToTitleCase[strAcc]
"The Lazy Dog Jumped On The Quick Brown Fox"
"Árv Ízt Űr Őt Ük Örf Úr Óg Ép"
ToTitleCase
has an eventful development history: in version 11, it is removed from among the built-ins, but is still acccessible from the "GeneralUtilities`"
context. It does not remove non-alphanumeric characters anymore from the string.
GeneralUtilities`ToTitleCase[str]
GeneralUtilities`ToTitleCase[strAcc]
"The Lazy Dog Jumped Over the Quick Brown Fox."
"Árv Ízt Űr Őt Ük Örf Úr Óg Ép"
WordBoundary
. $\endgroup$WordBoundary
is the second hit in V9. But see István's answer - those sorts of unexpected complications are reasons such questions should not be closed, at least not right away. $\endgroup$