How to get the last n characters of a string in Golang
In this post we will give you information about How to get the last n characters of a string in Golang. Hear we will give you detail about How to get the last n characters of a string in GolangAnd how to use it also give you demo for it if it is necessary.
we will learn how to get the last n characters of a given string in Golang.
In Golang, strings are the character sequence of bytes.
Getting the last n characters
To access the last n characters of a string, we can use the slice expression [] in Go.
Here is an example, that gets the last 3 characters from the following string:
country := "France"lastThree:= country[len(country)-3:]fmt.Println(lastThree)
Output:
nce
In the example above, we have passed [len(country)-3:] to the slice expression. so it starts the extraction at position len(country)-3 and extract the rest of a string.
Hope this code and post will helped you for implement How to get the last n characters of a string in Golang. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs