统计某个字符出现在字符串中的次数

    xiaoxiao2022-07-13  137

     本博客已经转移到:www.itwps.com 此博客后续不会再更新,详情请关注一下www.itwps.com 谢谢。  

    /** * 统计单字符在字符串中出现的次数 */ public int characterNum(String string,String character ) { //原来字符串长度 int len1 = string.length(); //character为要统计的字符 全部替换为空 String str = string.replaceAll(character, ""); //替换后的字符串长度 int len2 = str.length(); int lenNum = len1-len2; return characterNum; }

     

    最新回复(0)