Skip to content

Instantly share code, notes, and snippets.

@khoa-le
Created May 24, 2015 01:29
Show Gist options
  • Save khoa-le/751f0fac23ac760ffb66 to your computer and use it in GitHub Desktop.
Save khoa-le/751f0fac23ac760ffb66 to your computer and use it in GitHub Desktop.
Find and replace a character in a string in Go
package main
import (
"fmt"
"strings"
)
func main() {
str := " This string has many many spaces that need to be replaced "
fmt.Println(strings.Replace(str, " ", "", -1))
str2 := " This string has much much spaces that need to be replaced "
fmt.Println(strings.Replace(str2, "much", "many", 2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment