gosubstring

Go test string contains substring


How do I check if a string is a substring of another string in Go? For example, I want to check someString.contains("something").


Solution

  • Use the function Contains from the strings package.

    import (
        "strings"
    )
    strings.Contains("something", "some") // true