How to tell if a line is empty


#1

Hi

I’m doing a “Get full text” option on a certain line in a box. If the line contains a certain word, it’ll do a certain thing. The issue I’m having is if the line is empty.

I’ve tried Line.Length=0, Line="", Line.Contains(""), however none are working.

I’ve done the screen scraping method out of curiosity to see if it picks anything up, which brings up “AUTOMATIC method failed to scrape this UI Element”

Is there a way I can write something where it’ll tell me if the line is blank?

Any help would be greatly appreciated.

Thanks


#2

Hi,

Have you tried String.IsNullOrEmpty(yourVariable) and String.IsNullOrWhitespace(yourVariable)? These are my go-to’s in these situations.

Regards.


#3

Hi @Short,

I recommend you to do the following to be sure that you will get the expected result:

String.IsNullOrEmpty(Convert.ToString(Line).Trim())

Maybe your string has blank spaces and it may be impacting in your conditional statements, so the Trim() function will help you with that.

Hope this helps you!

Best regards,

Bruno Costa.


#4

Hi @andrzej.kniola and @brunoazev

Thanks for your responses! Neither of them worked until I put a space in the line I wanted to read, then they worked, so all sorted now.

Thank you again :slight_smile:


#5

Capture

I still get the error “Index was outside the bounds of the array.”


#6

Sorry, solved it! Using Array.Last in an assign activity and then pass it to the if statement