How to check if String ends with a Suffix String in Go?
How to check if String ends with a Suffix String in Go?
Go ? Check if String ends with Suffix
To check if a string ends with a given suffix string in Go language, call HasSuffix function of strings package, and pass the string and suffix string as arguments to it.
The syntax to check if string str ends with suffix string suffix using HasSuffix function is
strings.HasSuffix(str, suffix)
HasSuffix function returns a boolean value. It returns true if string str ends with string suffix .
Examples
In the following example, we take two strings, str and suffix , and check if str ends with suffix using HasSuffix function.
example.go
package main import (
"fmt" "strings" ) func main() { str := "Hello World" suffix := "World" if strings.HasSuffix(str, suffix) {
fmt.Println("The string ends with given suffix.") } else {
fmt.Println("The string does not end with given suffix.") } }
Output
The string ends with given suffix.
The string ends with given suffix.
Conclusion
In this Golang Tutorial, we learned how to check if a string ends with a given suffix string in Go programming language, with the help of example programs.
Golang Golang Tutorial Run Golang Program Golang If Else Golang Switch Golang For Loop Golang Comments Golang Functions Golang Array Golang Slice Golang Struct Golang Class Golang Range Golang Map Golang Goroutine Golang Channel
Golang String Operations Golang String Length Golang String Concatenation Golang Split String Golang String - Get Index of Substr Golang String to Uppercase Golang String to Lowercase Golang Convert String to Integer
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- golang int to int32
- a tour of go swtch
- golang convert string to lowercase tolower example
- sparql by example the cheat sheet
- parse string to int golang
- golang convert string to uppercase toupper example
- how to convert string to integer in golang
- how to check if string ends with a suffix string in go
- the go programming language part 1
- golang int to str
Related searches
- how to create a string in matlab
- how to separate a string in python
- how to check if ram is running
- javascript check if string is in array
- python check if string in list
- how to parse a string in python
- how to make a string in python
- typescript check if string is in array
- check if string is in list python
- how to assign a string in c
- how to print a string in python
- how to check if license suspended