描述:
鲍勃是一个懒人。
他想写一个方法,找出一个字符串里有几个字母和数字,你能帮助他吗?
例如:
“hel2!lo” –> 6
“wicked .. !” –> 6
“!?..A” –> 1
MyCode:
using System.Text.RegularExpressions;
public static class Kata
{
public static int CountLettersAndDigits(string input)
{
return Regex.Matches(input,"[a-zA-Z0-9]").Count;
}
}
CodeWar:
using System.Linq;
public static class Kata
{
public static int CountLettersAndDigits(string input)
{
return input.Count(c => char.IsLetter(c) || char.IsNumber(c));
}
}