Search code examples
arraysswiftlowercase

How to capitalize all strings in an array?


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.


Solution

  • You can use the map function like this:

    let array = ["BOY","GIRL","MAN"]
    
    let capitalizedArray = array.map { $0.capitalizedString}