How to replace all occurrences of character in a string in Go

2 Answers

0 votes
package main
 
import (
    "fmt"
    "strings"
)
 
func main() {
    s := "go php python c++ java"
     
    s = strings.Replace(s, "p", "X", -1)
     
    fmt.Println(s)
} 
     
 
   
      
/*
run:
       
go XhX Xython c++ java
   
*/

 



answered Aug 19, 2020 by avibootz
0 votes
package main
 
import (
    "fmt"
    "strings"
)
 
func main() {
    s := "go PHP python c++ java pascal"
     
    s = strings.Replace(s, "p", "X", -1)
     
    fmt.Println(s)
} 
     
 
   
      
/*
run:
       
go PHP Xython c++ java Xascal
   
*/

 



answered Aug 19, 2020 by avibootz
...