I used strings.Trim() in Golang to trim the first five characters.
However, the last "a" is always gone.
Why is that so?
Example:
sentence := "Kab. Kolaka Utara"
result := strings.Trim(sentence,sentence[:4])
fmt.Println(result)
Result: Kolaka Utar
I expected: Kolaka Utara
https://play.golang.org/p/R6UoKWNaVv
Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.
sentence[:4] is "Kab." Trim will remove all leading and trailing "k", "a", "b", ".".
https://golang.org/pkg/strings/#Trim
If you want to trim the first 5 bytes, then use:
result := sentence[5:]
playground example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With