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

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;

}

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页