2

I have one resume , i want to find user's contact number(Mobile no or Phone no) from the resume, Need any idea or solution or any assistance for achieving the goal .

What i Have tried so far....

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() + ", ";
                }
            }
        }
5
  • @Izzy please see the updated post Commented Oct 16, 2015 at 11:46
  • Just use a regex pattern like ,[\d]{10}, Commented Oct 16, 2015 at 11:54
  • Your example data doesn't look like a resume. Is there a reason you are showing us code that is splitting a CSV string? FYI that code can be reduced to var numString = string.Join(", ", strData.Split(',').Where(s => s.Length >= 10 && s.Length <=12)); Commented Oct 16, 2015 at 11:54
  • any example code with urs given pattern @MacroMan Commented Oct 16, 2015 at 11:55
  • @juharr my approach is bad i think Commented Oct 16, 2015 at 11:58

1 Answer 1

3

I would suggest that you use Regular Expression

Here is a sample code to find US Phone numbers:

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(); ;

         }
Sign up to request clarification or add additional context in comments.

2 Comments

is there are different pattern for eeach country ?
It depends on the format of the phone numbers. But I have used this one for other countries too: @"\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.