Menu Close

Go – How to check if string ends with given suffix in go golang

Here, We are going to learn about checking string ends with given suffix in go golang. We can do this by using HasSuffix() function of strings package in go golang.

HasSuffix() function tests whether the string s ends with suffix.

Function Prototype:

func HasSuffix(str string, suffix string) bool

Return Value:

It returns bool value. If string str ends with given suffix, then it return ‘true’ else ‘false’.

Example with code:

package main

import (

func main() {

	fmt.Println(strings.HasSuffix("TechieIndoor", "Indoor"))
	fmt.Println(strings.HasSuffix("TechieIndoor", "r")
	fmt.Println(strings.HasSuffix("TechieIndoor", "Techie"))
	fmt.Println(strings.HasSuffix("TechieIndoor", ""))



To learn more about golang, Please refer given below link.

Posted in golang, packages, strings

Leave a Reply

Your email address will not be published. Required fields are marked *