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.
Learn Go on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Go
Learn how to use Go (Golang), an open-source programming language supported by Google!Beginner Friendly6 hours