How to do multiple split text in less operations (activities)

I scrape web page and ending up with a text that i process multiple times, my end result is something like this before then final result.

But using multiple assigns to do the split i see is not efficient…I guess

[Sample text]

Item1  Normal
Item2  Normal
Item3  Normal

The result of the above is saved into a variable (string), “strMyMultiLine”. To split this further into single lines i have used the following split-function within an Assign activity to store it into a new variable (string) called strItem1, strItem2, strItem3.

strMyMultiLine.Split(new String(){Environment.NewLine},StringSplitOptions.None)(0)
strMyMultiLine.Split(new String(){Environment.NewLine},StringSplitOptions.None)(1)
strMyMultiLine.Split(new String(){Environment.NewLine},StringSplitOptions.None)(2)

This works perfectly so i got all the lines separated into single variables:

Item1 Normal

Item2 Normal

Item3 Normal

But i need to split them further, as you can see i have two spaces between Item and Normal ( ).
So i use the same code again to only keep the last bit of information “Normal” or whatever value might be there. Again, this is also run in a new Assign activity and assigned into yet a new variable.

strMyFinalSplit_status.Split(new String() {" "},StringSplitOptions.None)(1)

Normal

I assume or guess there could be some kind of pipe function or something i could use? How can i consolidate these two assign into one assign?

Ok,ok,ok, before you shoot me, there is indeed more assigns in my workflow as there is multiple white spaces of different that i have taken care of so if its possible to consolidate these into one would be awesome.

@FJ_Andersen

From everyline if you need only the second part with words…then you can use as below

VarMatches = System.Text.RegularExpressions.Regex.Matches(strmymultiline,"\w+$",System.Text.RegularExpressions.RegexOptions.MultiLine)

Varmatches is of type matchcollection or ienum(of match)

Now use for loop to get each value inside the loop by giving varmatches as input in for loop and change type argument to rgex.match

Now inside loop use currentitem in log message to see the output

Directly if you need to print all 3 without any loop then use as below …this will join with comma and print

String.Join(",",Varmatches.Cast(Of Match).Select(function(x) x.Value))

Hope this helps

Cheers

Thank you for your swift reply on my post here, I appreciate that. But i am not sure if i really understood this. Do you have a sample-flow for this?

@FJ_Andersen

Please check this (circled input,output and expression)

Expression: String.Join(“,”,Regex.Matches(strmymultiline,“\w+$”,System.Text.RegularExpressions.RegexOptions.MultiLine).Cast(Of Match).Select(function(x) x.Value))

cheers

1 Like

Will give it a try, thanks.

1 Like