In Go language, strings are different from other languages like Java, C++, Python, etc. It is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding.
In Go strings, you can check whether the string ends with the specified suffix or not with the help of HasSuffix() function. This function returns true if the given string ends with the specified suffix and return false if the given string does not end with the specified suffix. It is defined under the strings package so, you have to import strings package in your program for accessing HasSuffix function.
func HasSuffix(str, suf string) bool
Here, str is the original string and suf is a string which represents the suffix. The return type of this function is of the bool type.
Result 1: true Result 2: true Result 3: false Result 4: true Result 5: false Result 6: true Result 7: false
- Check if the Slice of bytes ends with specified suffix in Golang
- How to check the specified rune in Golang String?
- Check if the given characters is present in Golang String
- Check if the String starts with specified prefix in Golang
- How to trim suffix from the slice of bytes in Golang?
- How to check String for equality under Unicode case folding in Golang?
- Check If the Rune is a Letter or not in Golang
- Check if the given slice is sorted in Golang
- Check If the Rune is a Symbolic Character or not in Golang
- Check If the Rune is a Lowercase Letter or not in Golang
- Check If the Rune is an Uppercase Letter or not in Golang
- How to check equality of slices of bytes in Golang?
- Check If the Rune is a Space Character or not in Golang
- Check If the Rune is a Decimal Digit or not in Golang
- How to Split a String in Golang?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.