This is a creation in Article, where the information may have evolved or changed.
This function mainly counts the number of letters, the number of digits, the number of Chinese characters and other characters (note that Chinese characters are counted together with other characters)
The Go language code has
Func Main () { searchcount ("Golang python") searchcount ("I Hum" + "12345,54321" + "accidentally stepped on a piece of crap, It smells good")}func Searchcount (src string) { Letters: = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" letters = letters + strings. ToUpper (Letters) nums: = "0123456789" numcount: = 0 Lettercount: = 0 Otherscount: = 0 for _, I: = Rang e src { switch {case strings. Containsrune (Letters, i) = = true: Lettercount + = 1 case strings. Containsrune (nums, i) = = true: Numcount + = 1 default: otherscount + = 1 } } fmt. Println (Lettercount, Numcount, Otherscount)}
Python code is a little bit simpler
def searchcount (SRC): numcount=0 lettercount=0 othercount=0 for i in Src:if i.isdigit (): Numcount+=1 elif I.isalpha (): lettercount+=1 else:othercount+=1 Print (letter Count,numcount,othercount) searchcount ("Golang python") a= "I Hum" + "12345,54321" + "accidentally stepped on a piece of excrement, It smells good" searchcount ( A)