Last active
May 28, 2018 15:04
-
-
Save kevsersrca/e00f4355b425587ae73d56c51e43c1ce to your computer and use it in GitHub Desktop.
testing replace in go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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