- Package util;
- Public class Countstr {
- /**
- * There is a string that contains Chinese characters, English characters and numbers, please count and print out the number of individual characters
- * SMS sending platform, text message Word Count control Query method
- */
- public static void Main (string[] args) {
- //string str = "adasf AAADFD I am Chinese," 123 ";
- //string str = "Gold vest high-end commodity trading platform--2013 whole city Love carat diamond project pre-sale, 18 months, 30,000 start, annual 8%, pre-order please call Exhibition Heng Private Wealth: 18611297979";
- String str = "Zhan Heng Finance, established in Beijing in 2004, is one of the largest financial advisory institutions in China. obtained the National Independent Fund sale license. is one of the 10 core sponsors of the 2013 China Open tennis tournament. The company has been established for more than 10 years, in order to provide customers with a comprehensive family financial planning has accumulated a very rich experience. Currently has a high-end loyal customers more than 10,000, the allocation of customer funds more than 20 billion yuan, ranked in the top three industries. ";
- System.out.println ("[Total number of characters 1]:" +countsum (str));
- System.out.println ("--------------------");
- System.out.println ("[Total number of characters 2]:" +countsum2 (str));
- System.out.println ("--------------------");
- System.out.println ("[Total number of characters 3]:" +str.length ());
- }
- public static int countsum (String str) {
- int unicodecount = 0;
- int szcount = 0;
- int zmcount = 0;
- For (int i = 0; i < str.length (); i++) {
- char c = str.charat (i);
- if (c >= ' 0 ' && C <= ' 9 ') {
- szcount++;
- }Else if ((C >= ' a ' && c<=' z ') | | (c >= ' A ' && c<=' Z ')) {
- zmcount++;
- }else{
- unicodecount++;
- }
- }
- System.out.println ("Unicode:" +unicodecount);
- System.out.println ("number:" +szcount);
- System.out.println ("Letter:" +zmcount);
- int sum=szcount+zmcount+unicodecount;
- return sum;
- }
- public static int countSum2 (String str) {
- int abccount = 0;
- int numcount = 0;
- int spacecount = 0;
- int othercount = 0;
- char[] B = Str.tochararray ();
- For (int i = 0; i < b.length; i++) {
- if (b[i]>=' a ' &&b[i]<=' z ' | | b[i]>=' A ' &&b[i]<=' Z ') {
- abccount++;
- }Else if (b[i]>=' 0 ' &&b[i]<=' 9 ') {
- numcount++;
- }Else if (b[i]==') {
- spacecount++;
- }else{
- othercount++;
- }
- }
- int sum=abccount+numcount+spacecount+othercount;
- System.out.println ("The string contains the number of letters in English:" + abccount);
- System.out.println ("The number ofdigits contained in the string is:" + numcount);
- System.out.println ("The number of spaces contained in the string is:" + spacecount);
- System.out.println ("Other characters contained in the string are:" + othercount);
- return sum;
- }
- }
Count the number of occurrences of arrays, Chinese, English letters, spaces, and other special characters in a text