Replace all spaces in a string with '+'
Documentation on strings.Replace()
: http://golang.org/pkg/strings/#Replace
According to the documentation, the fourth integer parameter is the number of replacements. Your example would only replace the first space with a "+". You need to use a number less than 0 for it to not impose a limit:
tw.Text = strings.Replace(tw.Text, " ", "+", -1)
Use strings.ReplaceAll
tw.Text = strings.ReplaceAll(tw.Text, " ", "+")
If you're using an older version of go (< 1.12), use strings.Replace
with -1
as limit (infinite)
tw.Text = strings.Replace(tw.Text, " ", "+", -1)