In PHP we can do something like :
$result = str_replace($str,$array1,$array2);
Where $array1 and $array2 are array of elements, this makes php replace all array1 elements by array2 elements. Is there any equivalent to this using the Golang? I have tried the same php approach but it did not work :
str := "hello world"
array1 := []string {"hello","world"}
array2 := []string {"foo","bar"}
r := strings.NewReplacer(array1,array2)
str = r.Replace(str)
I know I can do something like :
str := "hello world"
array1 := []string {"hello","world"}
array2 := []string {"foo","bar"}
r := strings.NewReplacer("hello","foo","world","bar")
str = r.Replace(str)
That would work but I need to use arrays directly because the arrays of replacements will be created dynamically.