strings.Contains Function in Golang with Examples
strings.Contains Function in Golang is used to check the given letters present in the given string or not. If the letter is present in the given string, then it will return true, otherwise, return false.
func Contains(str, substr string) bool
Here, str is the original string and substr is the string that you want to check. Let us discuss this concept with the help of an example:
Explanation: In the above example, we check the presence of sub-string ‘for’ and ‘science’ in different strings. Since strings.Contains() function returns boolean value, it returns true in both the cases.
Example 2: Following example illustrates how the user can print the desired result instead of a boolean output:
Explanation: In the above example, we take a sub-string as ‘input’ and the main string as ‘str’. Then, we check if ‘Golang’ is present in the main string. If so, ‘Yes’ is returned as the output as shown above.
Please Login to comment...