How to add backslash to quotes in a string with 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

1 answer 219 views
219 views asked Aug 14, 2020 by avibootz
4 answers 244 views
3 answers 226 views
226 views asked Jun 10, 2023 by avibootz
1 answer 141 views
1 answer 177 views
177 views asked Aug 19, 2020 by avibootz
...