Replacing Parts of a #string
▻https://hackernoon.com/replacing-parts-of-a-string-cc1bb2f9ca07?source=rss----3a8144eabfe3---4
Every developer needs to know how to work with strings in the language they are using. The #go libraries makes replacing parts of strings easy for a developer. I will show three solutions for replacing parts of a string in Go.Solution 1The simple way is to use the Replace function from the strings package. This function takes in four values:s: This is the reference string.old: This is the value in the string we want to change.new string: This is the new string value.n: This is the number of times to do the replacement. If you use -1 it will replace all string values that are equal to the old value▻https://medium.com/media/43d9351ad089b4470f014a0ae8bd5466/hrefThis is the output:Mary had a little Gopher Gopher duckIf we change line 13 above to:out := strings.Replace(refString, "duck", (...)