Loop through in text file and extract data

Hello friends,

New problem that i need your help with.
This is my indata:

#Start=2021-10-20
#ID=1
Values=
1//
2//
3//
4//
5//

#Start=2021-11-20
#ID=2
Values=
13//
52//
32//
84//
65//

In my text file i have much more rows with Start, ID and values it can be up to ID up to 10000.
What i want to do is to select everything between #Start and the last value.
Can i select them and create an arry?
When i have had select thoose data i awant to write that into a excel workbook.

I have the data in a text file.

In the excel i want to structure it up lile

Value Start ID
1 2021-10-20 1
2 2021-10-20 1
3 2021-10-20 1
4 2021-10-20 1
5 2021-10-20 1
13 2021-11-20 2
52 2021-11-20 2
32 2021-11-20 2
84 2021-11-20 2
65 2021-11-20 2

What do you think out there?

/Anders

@Anders_Dahl1

Please follow

  1. Readthe data into a variable str
  2. Now split with #Start str.Split({"#Start"},StringSplitOptions.RemoveEmptyEntries) this gives you array of strings which can be stored in arr1
  3. now use for loop on arr1 to get each set of data
  4. System.Text.RegularExpressions.Regex.Match(Currentitem,"\d{4}-\d{2}-\d{2}").Value to get the date System.Text.RegularExpressions.Regex.Match(Currentitem,"(?<=ID).*").Value will give the id
  5. For getting values use str.Split({"="},Stringsplitoptions.None)(str.Split({"="},Stringsplitoptions.None).Count-1).Trim will give all values…can split the values on new line and use add data row

Cheers

mostly same as above

check this file

RegextoDatatable.xaml (13.5 KB)

Regards

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