Skip to main content

Command Palette

Search for a command to run...

Prefix Suffix

Published
1 min readView as Markdown
S
DevRel at StackGen | Formerly at Deepfence ,Tenable , Accurics | AWS Community Builder also Docker Community Award Winner at Dockercon2020 | CyberSecurity Innovator of Year 2023 award by Bsides Bangalore | Docker/HashiCorp Meetup Organiser Bangalore & Co-Author of Learn Lightweight Kubernetes with k3s (2019) , Packt Publication & also run Non Profit CloudNativeFolks / CloudSecCorner Community To Empower Free Education reach out me twitterhttps://twitter.com/sangamtwts or just follow on GitHub -> https://github.com/sangam14 for Valuable Resources

HasPrefix tests whether the string s begins with prefix:
strings.HasPrefix(s, prefix string) bool
HasSuffix tests whether the string s end with suffix:
strings.HasSuffix(s, suffix string) bool

package main
import ( 
 "fmt"
 "strings"   
 )
func main() {
var str string = "This is an example of a string"
fmt.Printf("T/F? Does the string \"%s\" have prefix %s? ", str, "Th") 
fmt.Printf("%t\n", strings.HasPrefix(str, "Th"))
}

Output: T/F? Does the string “This is an example of a string” have prefix Th? True

Go Playground

More from this blog

C

CloudNativeFolks Community

140 posts

CloudNativeFolks is non profit community that empower and educate about cloud native technology !