Reading text between two lines


#1

Hi all

I want to check if certain text is between two lines, e.g. - If “Receipt” is between “Photo of iPad” and “Test”

LineNames

Any help would be greatly appreciated

Thanks :slight_smile:


Moving specific content in notepad or word pad to Datatable
#2

Try this

strText = strText .Replace(Environment.NewLine,string.Empty)

bool Contains = Regex.Match(strText,"(?<=Photo of iPad)(.*?)(?=Test)").Value.Contains(“Receipt”)


How to get sub-string from string-data, where sub-string is dynamic each time when it loads on a webpage?
#3

Hi @vvaidya

Apologies for being a bit slow but I couldn’t work out if you meant do a match or an If (the condition throw me, and I didn’t think it would fit in an Assign) but neither work:

If error

Where am I going wrong?

Thanks!


#4

You don’t need matches in this case, just if condition. In your if condition remove quotes and you should be good.

If (Regex.Match(strQuote,"(?<=Photo of iPad)(.*?)(?=Test)").Value.Contains(“Receipt”))

Thanks,
Vinay


#5

Hi Vinay

That makes more sense, thanks.

Now I’m getting this error:

Saying that Regex is not declared. Is there something else I need to do for this?

Thanks!


#6

Hey @Short

You have to import “System.Text.RegularExpression” namespace in your project then you will be able to use Regex.

or can use as well like System.Text.RegularExpression.Regex but better to use import namespace approach.

Regards…!!
AKsh


#7

Amazing, thank you!