How to Split the text file in for each loop from and before some specific text. I need to split from I have a car and till Truck (which is before I have a car in the last line).
ex: I have a car
Bike
Truck
I have a car
I have a text file with multiple lines, i need to get specific data from each line by passing dynamic line number.
ex: I have a car
Bike
Truck
I have a car
Thank you.
Read text file using read text file activity.
beforeString= Split(inputString,“I have a car”)(0).ToString
afterString=Split(inputString,“I have a car”)(1).ToString
Hi @Vamsi_Krishna_Gogineni Thank you so much. This returns “System.Sting”. I have declared the variable as array. Also, Where do i need to provide the split variable which is “I have a car”
For this, you can use YourStringVariable.Split(“I have a car”, StringSplitOptions.RemoveEmptyEntries) which gives you the string between ‘I have a car’ in line 1 - 4. Like below, as one string, and as a first item of the resultant string array.
For this, you can use YourStringVariable.Split(New String() {Environment.NewLine},StringSplitOptions.None) which returns each line as an individual string in string array.
I’ve attached sample workflow for reference. Please run it and let me know if it helps.
Note: Please indicate the correct path of the txt file if you download it from here.
Hi @Suraj_B_Shetty , Thank you.
Below scenario could be infinite. “I have a car” is like a title, I need to split the data until next title and read the information under each title line by line. Lines may vary between one title to another. In the last we will not get the title, in this case i’m missing the last paragraph.
I have a car
Bike
Truck
I have a car
Bike
Truck
I have a car
Bike
Truck
I have a car
Bike
Truck
Hi @Vamsi_Krishna_Gogineni,
“I have a car” is like a title, I need to split the data until next title and read the information under each title line by line. Lines may vary between one title to another. In the last we will not get the title, in this case I’m missing the last paragraph.
I have a car
Bike
Truck
I have a car
Bike
Truck
I have a car
Bike
Truck
I have a car
Bike
Truck
Below is the input I’ve taken and I have named the values 1, 2, 3 & 4 to represent them as individual sets/ paragraphs.
And below is the output I’m getting. First I’m getting the individual sets and then by splitting it further, I get to access each value of that set/ paragraph. It works dynamically with any number of line in-between ‘I have a car’ to ‘I have a car’.
StringSplit.xaml (12.7 KB)
Please find the updated XAML attached. Initially I thought there are 2 scenarios irrelevant to each other. Hope the latest one helps.
I’m using 2022.4.6. I’m not able to get you XAML properly due to version difference.
I have Attached the text file. 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. I need to pass dynamic line value and check if there is a data.
Would you be able to share a screen shot of the flow, so that i can create my own flow and test it. Also the variable type. Thank you.
I’ve built the code accordingly and output is as below. Code is dynamic and fetching all the values
Below is the clear steps on what activities and code needs to be replicated on your end.
Code.docx (75.2 KB)
Once it is working, you can remove IndividualDataLines(8).Split(" ", StringSplitOptions.RemoveEmptyEntries)(0).ToString + " - " + from log message activity. I used it just to let you know about from which line the value is being extracted, by referencing to Name.
Aah! my bad, Please update the { and } position as mentioned below.
IndividualDataLines is array of string variable which contains each separate line as an item in the array. 8 is the position of the line we need in that array post split. Again from that line, we are splitting the data using tab space and getting the 1st and 2nd values to get person name and file name.
Please update { and } and positions for both the values printing in log message.
IndividualDataLines(8).Split({" “}, StringSplitOptions.RemoveEmptyEntries)(1).ToString + " - " +IndividualDataLines(8).Split({” "}, StringSplitOptions.RemoveEmptyEntries)(1).ToString
Please make sure to have tab space between " ", not just single space.
Is that a option to check the output array value in all the three steps. I couldn’t find what is the issue in my actual data.
If i can check the output, i will be able to know if its returning any value after the first step.
Yes, between assign and log message in the below screenshot, you can add one more log message and print currentItem
And after that you can use IndividualDataLines(8).Split(" ", StringSplitOptions.RemoveEmptyEntries) in another for each like below and print it’s currentItem
In my scenario, I update it to currentItem1 to keep it separate from above currentItem