Skip to content

Instantly share code, notes, and snippets.

@stefanwuthrich
Created March 26, 2019 03:54
Show Gist options
  • Save stefanwuthrich/7f38ec6f46182742993423bb96a0e91a to your computer and use it in GitHub Desktop.
Save stefanwuthrich/7f38ec6f46182742993423bb96a0e91a to your computer and use it in GitHub Desktop.
Replace first match of a Sstring item in a String Slice
func ReplaceStringInSlice(slice []string, replace string, with string) []string {
for i, v := range slice {
if v == replace {
slice = append(slice[:i], slice[i+1:]...)
slice = append(slice, with)
return slice
}
}
return slice
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment