Skip to content

Instantly share code, notes, and snippets.

@yamamushi
Created April 8, 2021 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamamushi/c7d49c76f8c6dead2536725bd0728dd4 to your computer and use it in GitHub Desktop.
Save yamamushi/c7d49c76f8c6dead2536725bd0728dd4 to your computer and use it in GitHub Desktop.
Go string between two strings
// Taken from
// https://stackoverflow.com/questions/26916952/go-retrieve-a-string-from-between-two-characters-or-other-strings/62555190#62555190
func GetStringInBetweenTwoString(str string, startS string, endS string) (result string,found bool) {
s := strings.Index(str, startS)
if s == -1 {
return result,false
}
newS := str[s+len(startS):]
e := strings.Index(newS, endS)
if e == -1 {
return result,false
}
result = newS[:e]
return result,true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment