To remove the first N characters of a string in Go, you can use string slicing starting from index N.
In this example,
str1
with a value of "Hello World"
.package main
import "fmt"
func main() {
str1 := "Hello World"
result := str1[3:]
fmt.Println("Modified string is:", result)
}
Modified string is: lo World
In this example,
str2
with a value of "apple"
.package main
import "fmt"
func main() {
str2 := "apple"
result := str2[2:]
fmt.Println("Modified string is:", result)
}
Modified string is: ple
In this tutorial, we learned How to Remove first N Characters in a String in Go language with well detailed examples.