I'm making a program to remove the letters from a string if they exsists. But the expected result will not come. The Program I have tried is below:-
package main
import (
"fmt"
"strings"
)
func main() {
strValue := "This is a string"
stringRemove := []string{"a", "an"}
var removalString string
for _, wordToRemove := range stringRemove {
removalString = strings.Replace(strValue, wordToRemove, "", -1)
}
fmt.Println(removalString)
result := strings.Replace(strValue, " ", "", -1)
result1 := strings.ToLower(result)
fmt.Println(result1)
}
Output:-
This is a string
thisisastring
fmt.Println(removalString)
output:-
This is string
This is a string
This is a string
thisisastring
Expected output:-
thisisstring