How find the line break using a particular Indea

I have to collect data after the word ‘summary’ and up to the second ‘Balance at xxxxx’
The line after ‘Balance at’ is not always the same.

example:

Summary:
Balance at xxxxxx
xxxxxx xxxx
xxxxx
xxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxx
Balance at xxxxxxxxxxxx
shdgjwhednsbdkj

I found the index of the Second ‘Balance at’ but I am not sure how to identify it till the line break.

Hi,

How about the following expression?

System.Text.RegularExpressions.Regex.Match(yourString,"Summary:[\s\S]*?Balance at[\s\S]*?Balance at.*").Value

Regards,

Hi @sunilkanth

so basically you can give the start and the count from where you want the identification to start from so I passed the Index of Balance at and search for new line after that line

str.IndexOf(Environment.newLine,str.IndexOf(“Balance at”,str.IndexOf(“Balance at”) + 1))
You can try like this

Here I passed the start of Balance at to find second balance at and then pass that index to start searching from second balance at to find the New line feed

cheers

I am getting the following error

The image is not a screenshot its mobile image hence the poor quality.

Hi,

For now can you try to remove the following red arrow pointed double quote?

image

Regards,

The output is empty

Hi @sunilkanth

Try this

str.IndexOf(Environment.newLine,str.IndexOf(“Balance at”,str.IndexOf(“Balance at”) + 1))

If the new line character is different then use \n or vbcrlf or \r\n in place of environment.Newline

cheers

Hi,

Can you share your input text?

Regards

I tweaked your answer and it worked. :grinning:

I added \s between Balance and at and \n at the end.

Thanks for the help

1 Like

(yourstring,“Summary:[\s\S]?Balance\sat[\s\S]?Balance\sat.*\n”)

1 Like