Remove x no. of rows from Notepad

HI All,

Need your quick help.

I want to remove x no. of rows from Notepad. I am using below expression. Here X is my Integer variable.

Below expression not working with x variable in the variable where as if I put any number in the expression, its is working fine.
Input_String is the output of Read Text Activity.

System.Text.RegularExpressions.Regex.Replace(Input_String,“^(.*\n){x}”,“”)

Can you help understanding what I am missing?

Thank You.

Can you give this a shot?

System.Text.RegularExpressions.Regex.Replace(Input_String,String.Format(“^(.*\n){0}”,“”, x.ToString))

If x=4 then this expression

String.Format(“^(.*\n){0}”,“”, x.ToString)

translates to

“^(.*\n){4}”,“”

Compilation Error: Reference to a non-shared member requires an object reference.

What happens if you substitute x with an actual value in your RegEx expression. Does it work?

Tried replacing x with variable and x.ToString with number. Same validation error.

@skg_161125 - Since X is a variable here… you have to give as shown below…

image

So in your case,

 System.Text.RegularExpressions.Regex.Replace(Input_String,"^(.*\n){"+x+"}","")

Hope this helps…

Note: If you want to use the shorter version , like regex.replace, regex.match please import system.text.regularexpressions in the import tab.

image

1 Like

Yes It worked @prasath17 with a small change. Thank you for you help.

System.Text.RegularExpressions.Regex.Replace(Input_String,“^(.*\n){”+x.ToString+“}”,“”)

Good to know…In my case, x is a string that’s why I didn’t use x.tostring. If x in Int in your case, then you have to use x.tostring.

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