I have problem to convert text into datatable from specific condition

Hello
I have text and i want to split with code and create into data tables.
For example :

"CodeNumber : 20 NumberPage : 1

No Date IdName Status
1 11/04/2022 01_abc Active
2 11/04/2022 02_def Acttive
3 12/04/2022 01_abc Inactive
4 12/04/2022 02_def Active

CodeNumber : 25 NumberPage : 1

No Date IdName Status
1 11/04/2022 03_ghi Active
2 11/04/2022 04_jkl Acttive
3 12/04/2022 03_ghi Inactive
4 12/04/2022 04_jkl Active"

I want to separate data with certain code numbers and make it into a data table. Any Idea how to solve it, can someone help me?

1 Like

Hi

Welcome to uipath forum

We can split this with Regex split and then convert that split text into datatable using generate datatable activity

Hope the below steps would help you resolve this

  1. Use a Assign activity like this

Arr_input = System.Text.RegularExpressions.Regex.Split(strinput.ToString.Trim, “CodeNumber: (\d){1,2} NumberPage: (\d){1,2}”)

Where arr_input is a variable of type array of string

  1. Now use a FOR EACH activity and pass the above array variable as input and change the type argument as string

  2. Inside the loop use a GENERATE DATATABLW activity and pass input as item.ToString and get the output as dt

  3. Then search as workbook in activity panel and drag the Write range activity next to the above generate datatable activity inside the loop

  4. Where mention the input as dt and enable add headers and mention sheet name as “Sheet”+Array.IndexOf(arr_input, item.ToString).ToString

  5. Finally inside the loop use a clear datatable activity and pass input as dt

Cheers @mr_Fajar_28

1 Like

Hi,

Another approach using Matches method :

mc = System.Text.RegularExpressions.Regex.Matches(strData,"CodeNumber : (?<CodeNumber>\d+) NumberPage : (?<PageNumber>\d+)\r?\n\r?\n(?<TABLE>[\s\S]+?)(?=\r?\n\r?\n|\s*$)")

Sample20220413-3.zip (3.0 KB)

Regards,

1 Like

Thank you for helping me

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.