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 244 views
3 answers 226 views
226 views asked Jun 10, 2023 by avibootz
1 answer 141 views
1 answer 157 views
1 answer 140 views
1 answer 131 views
1 answer 146 views
...