How to check if a string contains another in Swift
In this post we will give you information about How to check if a string contains another in Swift. Hear we will give you detail about How to check if a string contains another in SwiftAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to check if a string contains another string in Swift.
Checking the string contains another string
To check if a string contains another string, we can use the built-in contains() method in Swift.
The contains() method takes the string as an argument and returns true if a substring is found in the string; otherwise it returns false.
Here is an example:
let name = "alexa hut"let result = name.contains("hut")print(result)
Output:
true
False case:
let name = "alexa hut"let result = name.contains("rome")print(result)
Output:
false
Hope this code and post will helped you for implement How to check if a string contains another in Swift. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs