Created
March 26, 2019 03:54
-
-
Save stefanwuthrich/7f38ec6f46182742993423bb96a0e91a to your computer and use it in GitHub Desktop.
Replace first match of a Sstring item in a String Slice
This file contains hidden or 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
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