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! While you're at it, check out some resources Treehouse students have shared here.

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

iOS

how 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
Steven Deutsch
21,046 Points

Hey 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

hey 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