xxxxxxxxxx
fmt.Println(strings.ReplaceAll("hello wordl", "l", "L"))
fmt.Println(strings.Replace("hello wordl", "l", "L", 3))
xxxxxxxxxx
fmt.Println(strings.ReplaceAll("hello wordl", "l", "L"))
fmt.Println(strings.Replace("hello wordl", "l", "L", 3))
xxxxxxxxxx
re := regexp.MustCompile("(?m)[\r\n]+^.*substring.*$")
res := re.ReplaceAllString(s, "")
xxxxxxxxxx
fmt.Println(strings.ReplaceAll("hello wordl", "l", "L"))
fmt.Println(strings.Replace("hello wordl", "l", "L", 3))
xxxxxxxxxx
// Program using Replace() to replace strings
package main
import (
"fmt"
"strings"
)
func main() {
text := "car"
fmt.Println("Old String:", text)
// replace r with t
replacedText := strings.Replace(text, "r", "t", 1)
fmt.Println("New String:", replacedText)
}
xxxxxxxxxx
fmt.Println(strings.ReplaceAll("hello wordl", "l", "L"))
fmt.Println(strings.Replace("hello wordl", "l", "L", 3))