There are multiple ways to check if a string contains a specific substring.
Using in keyword
You can use in keyword to check if a string contains a specific substring. The expression will return boolean value.
The general syntax is the following:
Using the String.index
You can also use String.index method to find specific the index in the string where the substring starts.
Using the String.find
Also, you can use the find function from the String class. This function will return -1 if the substring is not present in the string.
Got an article suggestion?
Let us know
BY
NC
SA
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.