Created
April 8, 2021 17:33
-
-
Save yamamushi/c7d49c76f8c6dead2536725bd0728dd4 to your computer and use it in GitHub Desktop.
Go string between two strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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