Last active
September 18, 2020 16:41
-
-
Save tkausch/b22f9d67171584137bffbea30521d36a to your computer and use it in GitHub Desktop.
How to check whether a string contains any words from an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remember you can check wether a string contains a single word | |
let sentence = "I'was eating pommes with chees and an Apple for desert." | |
print(sentence.contains("Apple")) | |
// ... and we can also check if an array contains a word | |
let words = ["Apple", "Banana", "Orange"] | |
print(words.contains("Apple")) | |
// We can combine together do any of the words fulfill where clause? | |
print(words.contains(where: sentence.contains)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment