题解 | #判断各类型字符个数#

判断各类型字符个数

https://www.nowcoder.com/practice/4ccc155e474e4d4c83cfde116dcf2218

        //总字符个数
        int totalLen = str.length();
        //英文字母个数
        words = totalLen - str.replaceAll("[a-zA-Z]", "").length();
        //数字个数
        numbers = totalLen - str.replaceAll("[0-9]", "").length();
        //空格个数
        space = totalLen - str.replaceAll("[\\s]", "").length();
        //其他字符的个数
        other = totalLen - words - numbers - space;
全部评论

相关推荐

点赞 评论 收藏
分享
评论
6
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务