Escaping '.' character in string

Escaping '.' character in string



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.





The output should be same and is same for both building and running the file..The output you are saying should be when you chose new string as \\..
– Hamza Anis
Aug 22 at 0:06



\\.




1 Answer
1



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


go run


go build


go run





Yeah, that's what is strange about this. One thing, I am running in my mac but build and test is run on a RHEL server. Could this issue be because of OS?
– ravi
Aug 22 at 0:12






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế