Christopher Wade Cantley Christopher Wade Cantley - 5 months ago 13
iOS Question

How to capitalize each word in a string using Swift iOS

Is there a function to capitalize each word in a string or is this a manual process?

For e.g. "bob is tall"
And I would like "Bob Is Tall"

Surely there is something and none of the Swift IOS answers I have found seemed to cover this.

Answer

Are you looking for capitalizedString

Discussion
A string with the first character in each word changed to its corresponding uppercase value, and all remaining characters set to their corresponding lowercase values.

and/or capitalizedStringWithLocale(_:)

Returns a capitalized representation of the receiver using the specified locale.

For strings presented to users, pass the current locale ([NSLocale currentLocale]). To use the system locale, pass nil.

Comments