Splitting a single line String into strings to store in a DataTable

Hello guys,

I have the line below stored in a string variable:

Examples:

222 9723451 79 COMMU6 RR MISSI COMMU6 =UAY(J) S T 0101 20.05.2015 04395

324 2390197 79 APPLYTQ =3021 / APPLYTQ =1921 4500 18.10.2015 25236

1 ID – 3 characters
2. Product number – 7 digits
3. Local number = 79
4. System value – 15-19 characters
5. Database value – 15-19 characters
6. S = flag
7. I or A or T = flag
8. Level – 4 characters
9. Date – DD.MM.YYYY
10. Order number = 24836
11. / = Separator (sometimes it is there between System and Database values)

As you can see the string might miss some values (columns).

Is there a solid way to split these strings which can be applied to any all strings even if they are missing some columns?

Can Regex be used to split these strings? If yes please tell me how.

Please share your opinion or solutions with me :slightly_smiling_face:

And of course please do not hesitate to ask me question regarding this problem

I appreciate your help in advance

All the best :v:t2::v:t2::v:t2:

@srashidi yes regular expression can be the efficient solution. You can use like Match activity individually for every value you need.

Pattern
1 ID - ^\d{3}
2. Product - \b\d{7}\b

You can use lookahead and look behind syntaxes to get the rest of values.

  1. Local number - (?<=^\d{3}.\d{7})(\s*\d{2})
  2. Date - \b(\d{2}.){2}\d{4}\b

Needed more samples to get pattern for other values

@ranjith Thank you Ranjith for the solution but if you don’t mind, could you kindly give me an example how to use Match activity in UiPath because so far I wasn’t successful in make it work.

If possible please use these two examples:

222 9723451 79 COMMU6 RR MISSI COMMU6 =UAY(J) S T 0101 20.05.2015 04395

324 2390197 79 APPLYTQ =3021 / APPLYTQ =1921 4500 18.10.2015 25236

I really appreciate your help.

All the best

@srashidi,

First assign all the string to one variable and then divide the string by using split function.

String full = 222 9723451 79 COMMU6 RR MISSI COMMU6 =UAY(J) S T 0101 20.05.2015 04395

String str = full.split(" ".ToCharArray)

ID = str[0]
Product no = str[1]
etc…

@lakshman

You are right but this way if some of the fields missing then the robot doesn’t know and it will fill the datatable with the next value.

For example if we have System value and not Database value, the next value will be a flag and flag will be assigned to database value column!