5
[Golang] Test if a String Consists of Single Letter or Character
source link: http://siongui.github.io/2017/01/17/go-test-if-string-consist-of-single-letter-or-character/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
[Golang] Test if a String Consists of Single Letter or Character
January 17, 2017
Test if a string consists of single character or letter in Golang.
package main import ( "fmt" "strings" ) func IsConsistOfSingleCharacter(s, c string) bool { return strings.TrimLeft(s, c) == "" } func main() { fmt.Println(IsConsistOfSingleCharacter("#####", "#")) fmt.Println(IsConsistOfSingleCharacter("aabaa", "a")) fmt.Println(IsConsistOfSingleCharacter("哈哈哈哈", "哈")) fmt.Println(IsConsistOfSingleCharacter("哈哈嘻哈哈", "哈")) }
Tested on: Ubuntu Linux 16.10, Go 1.7.4 & Go Playground.
References:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK