Skip to content

Instantly share code, notes, and snippets.

@kevsersrca
Last active May 28, 2018 15:04
Show Gist options
  • Save kevsersrca/e00f4355b425587ae73d56c51e43c1ce to your computer and use it in GitHub Desktop.
Save kevsersrca/e00f4355b425587ae73d56c51e43c1ce to your computer and use it in GitHub Desktop.
testing replace in go
package main
import (
"io/ioutil"
"strings"
)
func replace(path string, oldValue string, newValue string) {
read, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
//Replace
newContents := strings.Replace(string(read), oldValue, newValue, -1)
err = ioutil.WriteFile(path, []byte(newContents), 0)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment