I want to replace a letter at a specific index in a string: aaaaaaa
-> aaabaaa
. Is there a built in way to do this? I wrote the following helper function to use in the mean time:
func main() {
input := "aaaaaaa"
output := replaceAtIndex(input, 'b', 3)
}
func replaceAtIndex(input string, replacement byte, index int) string {
return strings.Join([]string{input[:index], string(replacement), input[index+1:]}, "")
}