Converting multi-line scraped text into individual variables by line

I’m using a relative scrape in a Citrix based system on a target of text that contains multiple lines.

I am trying to avoid having to scrape each row individually as it is very slow. Is there a way scrape the entire, multiline target and convert each line of the scrape into its own variable?

Thanks,

Dan W.

1 Like

Yes, if you are able to return all of the text as one string you can then use the Split method, splitting the data on environment.Newline or vbcrlf (line break) to place them into a String Array from which point you select the value that you want e.g. myArray(2).ToString to get the second line.

MSDN guide to String Arrays:

https://msdn.microsoft.com/en-us/library/system.string.split(v=vs.110).aspx

2 Likes

Mr. Denton,

Thank you for your thoughtful response. Your suggestion of using the split method sounds like exactly what I’m looking for.

Originally, I was drawn to UiPath’s automation software as it advertised stating, “Your employees will use visual tools to graphically capture and automate repetitive activities on our designer screen (without a hint of coding).” I have no coding background, but I’m not opposed to learning.

After researching this method, and VB.NET in general, I have attempted to write an expression that will accomplish my goal of splitting the single string variable into an array by line and inserting it into the expression editor:

In stackoverflow, they suggest the following:

"Assuming you want to split on new lines - using String.Split will return an array containing the parts:

Dim parts As String() = myString.Split(new String() {Environment.NewLine},
StringSplitOptions.None)
This will be platform specific, so you may want to split on “\n”, “\r”, “\n\r” or a combination of them. String.Split has an overload that takes a string array with the strings you wish to split on."

But I couldn’t figure out what any of that means, so I dug into Mr. Denton’s link and ended up first creating an array of strings variable called Hold and second using the “assign” activity to assign to my new variable Hold, the value of Split(DescriptionScrape,vbCRLf)

I was then able to check my work using the write line activity and my string array of Hold(0), where the zero is the number of the line you want to return. Worked like a charm after only several hours of research; I should probably buy a book on VB.NET.

Hopefully this explanation will help other noobs like me :slight_smile:

2 Likes

Well, it turns out that the split function won’t work with my scrape as there can be an inconsistent number of rows in the data that I scrape. For example if my scrape is this:

1/10/16
1/8/16
1/8/16

I can use the split to create an array with 3 rows. Then I can assign each of those three rows to a variable so I can write them into a .csv

However, if the scraped area only contains 2 rows of data, then the split results in an array with only two rows. When I try to assign the 3rd, non-existent, row in the array to a variable, I get an error.

I tried to figure out how to include blank rows in the split, but was not successful. I am extremely frustrated.

Do anyone have an idea on how fix my problem?

What error are you getting? If you only have two items in your array and you are attempting to reference a third (e.g. arrTest(2).ToString - zero based) then you will get an error as this item does not exist. Instead you need to first count the number of items and only reference valid rows, alternatively you could use a null check or a Try Catch to ensure that if there is a problem it is handled correctly. Another possible solution might be to first remove any blank rows from your array. Where there’s a will there’s a way :slight_smile:

Richard

1 Like

Hi @dwilson , can you share how you split into array with 3 rows

i have same situation where i got the scrape and written with what you mentioned, but i am not able to split into a array with 3 rows , can you please share , actually my string has multiple space in-between so split with space is not solving

i want to use the last space to do the splitting

my scrap

pay plan
testing for uipath
hello world

Thank you and appreciate for your help