Golang, Python, statistics, numbers, the other number of Chinese characters.

Source: Internet
Author: User
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) 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.