To remove a single character from a Go string, you can use the strings.Replace()
function in combination with an empty string for the replacement
argument.
Here's an example that removes the character 'o' from the string "foo bar":
main.go155 chars13 lines
In the example above, strings.Replace()
takes three arguments: the original string (str
), the character to be replaced ("o"), and an empty string as the replacement. -1
is passed in as the n
argument to replace all occurrences of the character.
The resulting string with the removed character is stored in newStr
. We then print out newStr
, which should be "f bar" in this case.
gistlibby LogSnag