繁体   English   中英

从给定的字符串C#中查找电话号码

[英]Find phone number from given string c#

我有一个简历,我想从简历中找到用户的联系电话(手机号码或电话号码),需要任何想法或解决方案或任何协助以实现目标。

到目前为止我尝试过的...

var numString = "";
        string strData = ",38,,,,,,,,,,,,,,,,,,,,,,,,,,,,382350,,,,,0,,,,8141884584,,,,,,,,";
        char[] separator = new char[] { ',' };
        string[] strSplitArr = strData.Split(separator);
        for (int q = 0; q < strSplitArr.Length; q++)
        {
            if (strSplitArr[q] != "")
            {
                int no = 0;

                no = strSplitArr[q].Length;
                if (no >= 10 && no <= 12)
                {
                    numString += strSplitArr[q].ToString() + ", ";
                }
            }
        }

我建议您使用正则表达式

这是查找美国电话号码的示例代码:

string text = MyInputMethod();
const string MatchPhonePattern =
       @"\(?\d{3}\)?-? *\d{3}-? *-?\d{4}";

        Regex rx = new Regex(MatchPhonePattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);

        // Find matches.
        MatchCollection matches = rx.Matches(text);

        // Report the number of matches found.
        int noOfMatches = matches.Count;


        //Do something with the matches

        foreach (Match match in matches)
        {
            //Do something with the matches
           string tempPhoneNumber= match.Value.ToString(); ;

         }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM