VOOZH about

URL: https://www.geeksforgeeks.org/swift/how-to-check-if-a-string-contains-another-string-in-swift/

⇱ How to check if a string contains another string in Swift? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to check if a string contains another string in Swift?

Last Updated : 5 Jul, 2022

The Swift language supports different types of generic collections and a string is one of them. A string is a collection of alphabets. In the Swift string, we check if the specified string is present in a string or not. To do this task we use the contains() function. This function is used to check whether the specified string i.e. sequence of characters is present in the string or not. It will return true if the given string is present in the string otherwise it will return false. 

Syntax:

string.contains(char: charSequence)

Here string is an object of the string class.

Parameters: This function accepts a parameter that is illustrated below:

  • char: This parameter is a specified sequence of characters.

Return Value: This function will return true if the given string is present in the string otherwise it will return false. 

Example 1:

Output:

true
false

Example 2:

Output:

Blank space is present in the string
Computer Science is not present in the string
Comment
Article Tags:

Explore