码迷,mamicode.com
首页 > 其他好文 > 详细

Regex count lowercase letters

时间:2016-02-14 06:51:35      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

Description:

Your task is simply to count the total number of lowercase letters in a string.

 

Examples

 

LowercaseCountCheck("abc") == 3
LowercaseCountCheck("abcABC123") == 3
LowercaseCountCheck("abcABC123!@€£#$%^&*()_-+=}{[]|\‘:;?/>.<,~"") == 3
LowercaseCountCheck("") == 0
LowercaseCountCheck("ABC123!@€£#$%^&*()_-+=}{[]|\‘:;?/>.<,~"") == 0
LowercaseCountCheck("abcdefghijklmnopqrstuvwxyz") == 26

 

using System.Text.RegularExpressions;

public class Kata
{
  public static int LowercaseCountCheck(string s)
  {
       string pattern = "[a-z]";
            Regex regex = new Regex(pattern);
            var temp = regex.Matches(s);
            return temp.Count;
  }
}

[a-z]是匹配小写字母

用了Matches之后,会把每一个符合条件的提取出来

最后用Count计数

 

Regex count lowercase letters

标签:

原文地址:http://www.cnblogs.com/chucklu/p/5188544.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!