Contains()
Published Jul 4, 2023
Contribute to Docs
The Contains()
function returns a boolean value indicating whether a given substring is present or not in a given string. The method returns true
if the substring is present, otherwise it returns false
.
Syntax
strings.Contains(str, sub_str)
Where str
is the original string and sub_str
is the substring to check against the original string.
Example
The following example demonstrates the use of the strings.Contains()
function.
package mainimport ("fmt""strings")func main() {fmt.Println(strings.Contains("folder","old"))fmt.Println(strings.Contains("folder","code"))}
The output will be:
truefalse
Codebyte Example
The following example is runnable and uses the strings.Contains()
function to determine if the given value is present in the string codecademy
.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.