有趣生活

当前位置:首页>科技>c编程入门教程C编程技巧之

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

发布时间:2026-07-18阅读(0)

导读引用方法stringstr="13999999999,18155566611";inti=ReturnPhoneCount(str);//结果:i=2代码/....

引用方法

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;

}

Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图