c编程入门教程(C编程技巧之)(1)

引用方法

string str = "13999999999,18155566611";

int i= ReturnPhoneCount(str);

//结果: i=2

代码

/// <summary>

/// 判断有多少个手机号并返回手机号码的数量

/// </summary>

/// <param name="str"></param>

/// <returns></returns>

public static int ReturnPhoneCount(string str)//将字符通过正则表达式分解成list 并返回list 数量;

{

string x = @"1[3456789]\d{9}";

MatchCollection Matches = Regex.Matches

(str, x, RegexOptions.IgnoreCase);

StringBuilder sb = new StringBuilder();

var list = new List<string>();

foreach (Match NextMatch in Matches)

{

list.Add(NextMatch.Value);

}

string[] arr;

arr = list.ToArray();

int TelCount = arr.Length;

return TelCount;

}

,