6

I have a array of strings, but all the stings are written in upper case letters. Is there a way for me to make all the strings in the array to lower case, (and with capitalisation)

array = ["BOY","GIRL","MAN"]  
// func to convert it to array = ["Boy","Girl","Man"]  

Is there a way to do this, without rewriting the content of the array with lower case letters. I have a very long array of strings in upper case letters.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Tarjerw
  • 505
  • 1
  • 5
  • 12

2 Answers2

24

You can use the map function like this:

let array = ["BOY","GIRL","MAN"]

let capitalizedArray = array.map { $0.capitalizedString}
totiDev
  • 5,189
  • 3
  • 30
  • 30
7

SWIFT 4:

The property capitalizedString has changed to capitalized.

let array = ["BOY","GIRL","MAN"]

let capitalizedArray = array.map {$0.capitalized}
Marcy
  • 4,611
  • 2
  • 34
  • 52