Hi all,
I am trying to extract some data in a text file. I tried to use my data.Split({“special”,”good”},StringSplitOptions.None) to extract data between words special and good. However, these two words appear many times in the text file and I only want to extract the latest data. My logic is to count how many times they appear and only choose the last time to extract, but I dun know how to write it…
Anyone can help!
Many thanks.
varunk
(Varun Kumar)
April 1, 2019, 3:24am
2
Hi @raymondhui ,
Use regular expression
write pattern for that & get the data
Hi @varunk
Pattern = “special”?
But I dun want to get all of the result but only the last one.
varunk
(Varun Kumar)
April 1, 2019, 3:46am
4
Hi @raymondhui ,
You need to write pattern according to groups,then latest means from file starting or ending
According to that you can take that group
Hi @varunk
I am not familiar with regular expression, especially patterns, would you mind share more about it?
Many thanks
data.Split({“special”,”good”},StringSplitOptions.None)(data.Split({“special”,”good”},StringSplitOptions.None).Length-2)
Simply take the second last item in your array.
Use
(?<=special)(.*?)(?=good)
in matches activity you will get an IEnumerable of Matches.
in that you can use Variable .LastOrDefault
Hi @Vijay_Tulsalkar
Thx bro but actually I need to extract data between first one and last one. Would u like to show me the steps?
Thanks
@raymondhui
can you explain with an example. can you share the TEXT here and the end result required?
@Vijay_Tulsalkar
Sorry mate can’t upload the text file right now and only can upload the image for your reference.
Attached you can find Identifier Report EL-888 and last pages TRANSATION TOTAL RECORD. Supposed this one is the result and these data are captured from a raw text files.
Many thanks
Hi @HalmiNordin
Yes but it’s not returning value I want
What value do you actually want?
Would upload txt file later thx mate
@raymondhui .
I’m still confused, as per my understanding just try out this approach.
Split with special then take the lastordefault index of it and store in variable.
then split the variable with good and take the first index value.
the code might look something like this
variable1 .Split({“special ”},StringSplitOptions.RemoveEmptyEntries).Last.ToString.Split({“good ”},StringSplitOptions.RemoveEmptyEntries)(0)