I have an array of correctly formatted phone numbers:
string[] phoneNumbers = {"US +1 866 XXX XXXX",
"UK +44 (0)XXX XXX XXXX",
"Singapore +65 XXXX XXXX"
};
The phone numbers that I am getting as input corresponds to one of these items in the list, however it is formatted slightly different. The inputs can be one of these 3. Note, the country names at the beginning are NOT included.
- (866) XXX-XXXX
- +44 (0) XXX XXXXXX
- +65 XXXXXXXX
As you can see, my input is slightly different formatting than the array.
My question is, what is a good way to pull the correct formatted version of the number out of the array when I have an input that is formatted differently.
I am not requesting someone to do this for me, as I can do the code fine. The logic is getting me for some reason right now.
What I have thought about doing, is a parallel phone numbers array with all of the incorrectly formated inputs and get the index of the item in that array and get the corresponding input of the correct array. Does this seem logical? Is there a better, faster way?
EDIT:
Currently I am getting the job done with this:
for(int i=0; i<phoneNumbers.Count(); i++)
{
var tempDialInNumber = (from t in input //input from the user
where char.IsDigit(t)
select t).ToArray();
string tDialInNumber = new string(tempDialInNumber);
var tempDigitPhoneNumber = (from t in phoneNumbers.GetValue(i).ToString()
where char.IsDigit(t)
select t).ToArray();
string tDigitPhoneNumber = new string(tempDigitPhoneNumber);
if (tDigitPhoneNumber.Contains(tDialInNumber))
{
dialInNumber = phoneNumbers.GetValue(i).ToString();
}
}