转义“。” 字符串中的字符

I am trying to escape all occurrence of '.' character in a string with backslash. When I run my Go code it works fine but when I compile and build the binary and then run it, it adds one more backslash.

s := "strings.test"
i := strings.Replace(s, ".", "\\.", -1)

I even tried

s := "strings.test"
i := strings.Replace(s, ".", `\.`, -1)

Output: "strings\\.test"

Expected Output: "strings\.test"

Not sure what is the difference between running the main.go vs building the project and then running it.

Are you sure about your output? This Go Playground gives me your desired output https://play.golang.org/p/fGzLeE_3h6h

Compiling does the same, I get the correct output... Are you sure your code is running fine (with the values you expect)?

go run does the same as go build however go run executes the compiled binary for you, more like a shortcut