To remove a specific character from a string in Go, you can use the `strings.ReplaceAll` function.
In this example,
strings
package.str
with a value of "Hello World"
.ReplaceAll
function from the strings
package to replace all occurrences of 'l' with an empty string in str
.str
.package main
import (
"fmt"
"strings"
)
func main() {
str := "Hello World"
modifiedStr := strings.ReplaceAll(str, "l", "")
fmt.Println("Modified string:", modifiedStr)
}
Modified string: Heo Word
In this example,
strings
package.str
with a value of "apple"
.ReplaceAll
function from the strings
package to replace all occurrences of 'a' with an empty string in str
.str
.package main
import (
"fmt"
"strings"
)
func main() {
str := "apple"
modifiedStr := strings.ReplaceAll(str, "a", "")
fmt.Println("Modified string:", modifiedStr)
}
Modified string: pple
In this tutorial, we learned How to Remove specific Character from a String in Go language with well detailed examples.