2

I'm looking to capitalise the first letter of each word in a string. For Example:

stack overflow --> Stack Overflow

STACK OVERFLOW --> Stack Overflow

Does anyone know to accomplish this in swift 3?

user4174219
  • 427
  • 5
  • 13

1 Answers1

18

Call capitalized function on your string as follows.

var str = "hello, playground"
str.capitalized
print(str.capitalized)

Output Hello, Playground

Nishant Tyagi
  • 9,893
  • 3
  • 40
  • 61