How to get last 2 lines from a string

Hello everyone,

I am trying to get the last 2 lines of string examples below, Names are variable and need to data scrape the address only which resides on last 2 lines. How do I do string manipulation for this? Regex?

Input string variable:
John Doe
1234 MyStreet Way,
WestField, PA 1234-6703,

John Doe
Jane Doe
1235 MyStreet Way,
WestField, PA 1234-6703,

Expected result:
1235 MyStreet Way,
WestField, PA 1234-6703,

Thanks you in advance!

@MaeHU

Try this

String.Join(Environment.Newline,str.Trim.Split({Environment.Newline},Stringsplitoptions.None).Skip(str.Trim.Split({Environment.Newline},Stringsplitoptions.None).Count-2))

Or

String.Join(Environment.Newline,System.Text.RegularExpressions.Regex.Split(str.Trim,"\n").Skip(System.Text.RegularExpressions.Regex.Split(str.Trim,"\n").Count-2))

Cheers

Hi,

Can you try the following expression.

Last 2 lines of the string.

System.Text.RegularExpressions.Regex.Match(yourString,".*\r?\n.*(?=\s*$)").Value

Last 2 lines of each part

mc = System.Text.RegularExpressions.Regex.Matches(yourString,".*\r?\n.*(?=\r?\n\r?\n|\s*$)")

Sample20230329-1L.zip (2.6 KB)

Regards,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.