Hi Team,
I have phone number array containing below string
(123) 456-7890 extension 2
I need extract phone number and extension number .the challenge is ,user can provide combination of any letter within extension .How to proceed that ?
Ex
- (123) 456-7890 extn 2
- (123) 456-7890 ex 2
- (123) 456-7890 extraction 2
-
- 456-7890 x 2
If MyStr
is the original string with the phone number, do the following:
1.) Assign MyStr = System.Text.RegularExpressions.Regex.Replace(MyStr, "[^0-9]", "-")
.
2.) Create a new String array variable PhoneSplit
, and assign it as PhoneSplit = MyStr.Split("-"c)
.
3.) Use a For Each activity to iterate over PhoneSplit
, and use Add To Collection to add each item in PhoneSplit
to list PhoneList
if the current item is not an empty string (i.e. item <> String.Empty
).
4.) Your phone number is PhoneList(0) + "-" + PhoneList(1) + "-" + PhoneList(2)
.
5.) Your extension is set to Nothing
if PhoneList.Length < 4
. Otherwise, your extension is PhoneList(3)
.