Handling multiple delimiters

Input Data -

ID Name Location PrimaryPhoneNo/AlternatePhoneNo
100 Amit Banglore 5678945379#$9785463241
101 Ajay Hyderabad 7985679128&9796951269
102 Ramesh Pune 9965423781*@5671439856
103 Suresh Delhi 9561796456^@*#9552706398

Expected Output-

Name Primary Number Alternate Number
Amit 5678945379 9785463241
Ajay 7985679128 9796951269
Ramesh 9965423781 5671439856
Suresh 9561796456 9552706398

To extract alternate number, i have written this expression in assign activity, but its giving error,

CurrentRow(“PrimaryPhoneNo/AlternatePhoneNo”).ToString.Split(“#”.ToCharArray)(1).Split(“&”.ToCharArray)(1).Split(“@”.ToCharArray)(1).Split(“*”.ToCharArray)(1).Split(“$”.ToCharArray)(1).Split(“^”.ToCharArray)(1)

Error -

Is there any way to resolve this error…

Hi @NILESH.BOT369 ,

Few quick qns,
1.Are u expecting always an alternate number after the Primary number?
2.If Answer to 1 is Yes,then is the alternate number always a 10 digit number ?
3.If Answer to 2 is Yes, then you can just extract 10 letters from the last/end of the string by using substring method

Thank you for your reply,

  1. Yes
  2. No.

Hi @NILESH.BOT369 ,

Length of the Alternate Number is not always 10?But I see from your example the ALternate Numbers are 10 digits
9785463241
9796951269
5671439856
9552706398

Could you confirm

Yes, but lets consider alternate numbers are not 10 Digit numbers for our example.

Hi,

Can you try the following sample?

dtResult = dt.AsEnumerable.Select(Function(r) dtResult.LoadDataRow({r(1),System.Text.RegularExpressions.Regex.Match(r(3).ToString,"\d+").Value,System.Text.RegularExpressions.Regex.Match(r(3).ToString,"\d+$").Value},False)).CopyToDataTable

Sample
Sample20240307-3.zip (9.4 KB)

Regards,

HI @NILESH.BOT369

Please check the below xaml and the attached excel file:
TIME.xlsx (10.6 KB)
Sequence40.xaml (11.8 KB)

Regards

If thts the case You can try the below steps:

Replacing anything character other than 0-9 with A
Then fetch the numbers:
Primary No= StrVar.Substring(0,System.text.RegularExpressions.Regex.Replace(StrVar,“[^0-9]”,“A”).IndexOf(“A”))

AlternateNo=StrVar.Substring(System.text.RegularExpressions.Regex.Replace(StrVar,“[^0-9]”,“A”).LastIndexOf(“A”)+1)

Hello @vrdabberu,
LINQ works perfect :slightly_smiling_face:, thank you… :+1:

@Yoichi
Works perfect, thank you… :+1:

Hi @gRao,
Thank you,
Works perfect… :+1:

“/d+$” this matches multiple digits from right end, is this correct understanding?

Nope. It’s necessary to use backslash instead of slash as the following.

\d+$

Sorry, My Bad,

“\d+$” this matches multiple digits from right end, is this correct understanding now?

Yes, your understanding is right. The following explanation also helps you.

Ohh, Got it,
May i know where are you seeing this window?

It’s regex101.

Please note that it’s necessary to check .net(C#) at Flavor if you need to check/buid regex pattern for UiPath.

image

Regards,

Thank you,
This really helps… :+1: :slightly_smiling_face: