Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
samarth sharma
1,758 Pointshow to identify keywords in a string
how do i identify a particular word in a string and return something in swift 2.0
something like a search engine ?
1 Answer

Steven Deutsch
21,046 PointsHey samarth sharma,
You can use the contains() method on a String. It takes in a string as its argument and returns a boolean based on the result. For example:
let aString = "This is a string"
let result = aString.contains("is")
print(result) // will print true
Good Luck
samarth sharma
1,758 Pointssamarth sharma
1,758 Pointshey thanks for the help but i am trying to find a particular word in an input of string type
suppose the input string says "hey i like swift 2.0"
i want to find the keyword "swift" from the input.
likewise i want to be able to find multiple keywords that i mention to be found within an input