How to replace first two occurrences of character in a string in Go

1 Answer

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

 



answered Aug 19, 2020 by avibootz
...