In Go, you can find the index of the first occurrence of a substring in a string using the strings.Index()
function. Here's an example:
main.go171 chars15 lines
In this example, strings.Index()
returns the index of the first occurrence of "llo"
in "Hello, World!"
, which is 2
.
Note that strings.Index()
returns -1
if the substring is not found in the string.
gistlibby LogSnag