How to replace first occurrence of substring in a string 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, "GO", "C++", 1)
     
    fmt.Println(s)
} 
     
 
   
      
/*
run:
       
go php PHP C++ Python go GO
   
*/

 



answered Aug 19, 2020 by avibootz
...