Remove 2nd line in string

i have a string that look like
“hello this is
a string
test”
i want to remove the second line
how can i do this?

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"(?<=^.*\n).*\n","")

Regards,

1 Like

this works. thank you
for future reference if i want to remove say the nth line how would that work?

Hi,

If n=4, the following will work if there are 5 or more lines. (Please set n-1 between { and } )

System.Text.RegularExpressions.Regex.Replace(yourString,"(?<=^(.*\n){3}).*\n","")

Regards,

1 Like

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