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

1 Answer

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

 



answered Aug 19, 2020 by avibootz
...