Split Text into multiple line and read a specific data

Hello All,
I have Attached the text file here data as a text here. I need to split the data from ABCDE123 before ABCDE123 of next item and then read specific value from each line item. I have the position of each data. Ex: Line 9: Position 11-13 for File name(AAA). I need to pass dynamic line value and check if there is a data.
I have tried YourStringVariable.Split(New String() {Environment.NewLine},StringSplitOptions.None), but this returns System.String though the variable is array of string.

Thank you.
New Text Document.txt (1.0 KB)

Hi,

Can you share your expected output in details? And also which part is fixed and which part is vary?

Regards,

Hi @Yoichi,

I have shared the sample data and the requirement . Thank you.

  1. Need to split the data from 1ABCD123 till (before next 1ABCD123) – save as different set of data
  2. Same set needs to be repeated for next set of data (From next 1ABCD123)

Hi,

How about the following?

Sample20230307-1L.zip (4.3 KB)

Regards,

1 Like

Hi @Yoichi , Thank you. This is great.

I have missed to mention few data in the file. I need to get the below data as well. Would you be able to help with the regex for these.

  1. Line 3 - “AMOUNTIS ITEM LIST” (Alphabets) no of alphabets may differ for each file
  2. Line 4 - “ABCDEFG12” (Alpha numeric value)
  3. Line 6 - PAID DATE: “OCT 25,2022” (Date)
  4. Line 10 - "LIST OF ITEMS " (Alphabets) no of alphabets may differ for each file

Hi,

Can you try the following sample?

Sample20230307-1Lv2.zip (4.5 KB)

Regards,

Thank you. This is working.

Can you please explain the concept of below expressions for my understanding.

  1. strAmountItemList = System.Text.RegularExpressions.Regex.Match(currentItem.Value.Trim,“(?<=(.\r?\n){2}\s\S.?\s{2,})\S.(?=\r?\n)”).Value.Trim
  2. strAfterAmoutItemList = System.Text.RegularExpressions.Regex.Match(currentItem.Value.Trim,“(?<=^(.\r?\n){3}).”).Value.Trim - What “{3}” refers to
  3. strListOfItems = System.Text.RegularExpressions.Regex.Match(currentItem.Value.Trim,“(?<=^(.\r?\n){9}).”).Value.Trim

Hi,

^(.*\r?\n){3} matches 3 lines from the beginning of the string. So (?<=^(.*\r?\n){3}).* returns 4th line.

(?<=(.*\r?\n){2}\s*\S.*?\s{2,}) matches 2 lines from the beginning of the string and words before 2 or more spaces. So, (?<=(.*\r?\n){2}\s*\S.*?\s{2,})\S.*(?=\r?\n) returns string after “some words and 2 or more spaces” in the 3rd line

Regards,

Make sense. Thank you

Hi @Yoichi,

  1. This code provides only one row under each set of data. If there are more than one row its skipping those rows and moving into next set of data.
  2. ABSUB.STU.CODE - This is new column added in the file, I tried to declare this but getting group invalid error.

Thank you for your support !

Hi @Yoichi,

Could please explain the below regex which might help me to try any solution for current issue.

System.Text.RegularExpressions.Regex.Matches(strItemsPart,“(?<=^|\n)[\s\S]+?(?=\r?\n[^\r\n\S]+\r?\n|$)”)

Thanks !