Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a list of words that contains upper case letters in swift?

Tags:

string

swift

I would like to generate a list of words form a given string where each listed word contains at least an upper case letter.

Having a string like this one:

let str: String = "Apple watchOS 3 USA release date and feature rumours."

I would like to get an array like this:

var list: [String] = ["Apple", "watchOS", "USA"]

What is the best way to do this?

like image 394
Cue Avatar asked Dec 06 '22 17:12

Cue


1 Answers

var list = str.componentsSeparatedByString(" ").filter{ $0.lowercaseString != $0 }
like image 87
NSGangster Avatar answered May 17 '23 23:05

NSGangster