java-统计字符串中的汉字个数

1 String text = "你好,,.。wo";
2 String Reg="^[\u4e00-\u9fa5]{1}$";//正则
3 int result=0;
4 for(int i=0;i<text.length();i++){
5     String b=Character.toString(text.charAt(i));
6     if(b.matches(Reg))
7         result++;
8     }
9 }

原文地址:https://www.cnblogs.com/flyinghome/p/12144630.html

时间: 2024-08-03 01:44:38

java-统计字符串中的汉字个数的相关文章

java统计字符串中字符及子字符串个数

import java.util.Scanner;public class Counter { static Scanner scanner = new Scanner(System.in); public static void count(String s) { int low, upper, num, others; low = upper = num = others = 0; for (int i = 0; i < s.length(); i++) { if (Character.is

问题 C: c#统计字符串中数字字符的个数

题目描述 假设有一个GetNumber方法(参数为字符串strSource),编写一个静态方法可以用来统计字符串strSource中数字字符的个数. 输入 输入一个字符串strSource 输出 strSource字符串中数字字符的个数 样例输入 .wrapper {position: relative;} #input {position: absolute;top: 0;left: 0;opacity: 0;z-index: -10;} copy asffkl8asjkfjklas3jdf9

统计字符串中单词的个数

1.单纯统计单词个数,单词与单词之间只考虑空格的情况 // word_statistic.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include <string> using namespace std; #define M 10000 #define N 20 int _tmain(int argc, _TCHAR* argv[]) { char str1[M]={0};

统计字符串中大写字母个数

可将字符串转为字符数组,然后对数组进行遍历,进而统计大写字母的个数. 下面给出代码: import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner in = new Scanner(System.in); String str = in.nextLine(); int count = 0; char ch[] = str.toCharArray(); //转为字符数组 f

关于统计字符串中重复字符个数

一般使用map集合的键不唯一来统计 map.containsKey(b)//判断map集合键中是否包含b 若果不包含就将b作为键存入集合中值为1 map.put(b,1); 如果键中包含那么键不变,值在原来的基础上加1 map.put(b,map.get(key)+1); 代码展现 for(Character key : keySet){ if(!map.contiansKey(b)){ map.put(b,1); }else{ map.put(b,map.get(key)+1); } }

java 匹配字符串中的中文个数

/*** 匹配字符串中有多少个中文* wangxq 2015年7月1日 16:18:52* @param recordStr* @return*/ public Integer parseRecordStr(String recordStr){ Integer countNum = 0; if(recordStr){ // 要匹配的字符串 String reg_charset ="[\\u4E00-\\u9FA5]"; Pattern p = Pattern.compile(reg_c

正则表达式统计字符串中数字的个数

#coding=utf-8import stringimport restr='i have 300 yuan, you 234 234 give me 200 again, then i have 500 yuan'iList= re.findall(r"\d+",str)print "string:",strprint "total digit number:",len(iList) 原文地址:https://www.cnblogs.com/

统计字符串中汉字的个数

字符串可以包括数字.字母.汉字或者其他字符.使用Charater类的isDigit()方法可以判断字符串中的某个字符是否为数字, 使用Character类的isLetter()方法可以判断字符串中的某个字符是否为字母. 本案例将介绍用"正则表达式"来判断字符串中的某个字符是否为汉字,并统计该字符串中汉字的数量. 关键技术: Java中提供Pattern用于正则表达式的编译方式,该类的静态方法matches()可以执行正则表达式的匹配.该方法的声明如下: public static bo

java统计文本中某个字符串出现的次数

原文: java统计文本中某个字符串出现的次数 源代码下载地址:http://www.zuidaima.com/share/1550463297014784.htm 统计文本中某个字符串出现的次数或字符串中指定元素出现的次数 文件样本: 程序查找的上此文件带"a"的字符在多少次 结果: package com.zuidaima.util.string; import java.io.*; /** * @author www.zuidaima.com **/ public class C