Your task is simply to count the total number of lowercase letters in a string.
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计数
原文:http://www.cnblogs.com/chucklu/p/5188544.html