Go test string contains substring

Warlike Chimpanzee picture Warlike Chimpanzee · Jul 23, 2017 · Viewed 89.8k times · Source

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

Answer

Warlike Chimpanzee picture Warlike Chimpanzee · Jul 23, 2017

Use the function Contains from the strings package.

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