How to escape single quotes in Go

1 Answer

0 votes
package main
 
import (
    "fmt"
    "strings"
)
 
func main() {
    s := "go 'php' PHP GO 'Python' go GO"
     
    s = strings.Replace(s, "'", "\\'", -1)
     
    fmt.Println(s)
} 
     
 
   
      
/*
run:
       
go \'php\' PHP GO \'Python\' go GO
   
*/

 



answered Aug 19, 2020 by avibootz

Related questions

4 answers 404 views
3 answers 376 views
376 views asked Jun 10, 2023 by avibootz
1 answer 227 views
1 answer 246 views
1 answer 245 views
1 answer 205 views
1 answer 240 views
...