lmalave lmalave - 2 months ago 9
C# Question

Remove \r\n\r\n from the results in a textbox

I have the following code:

txtcmdApp.Text = RunScript(@"if (Get-Process greenshot -ErrorAction silentlycontinue –ComputerName " + txtWSName.Text + " ) {'Open'} else {'Not Opened'}");


The results shown in the textbox is Not Opened but, when I use a breakpoint it is showing the following in code:

txtcmdapp|{Text = "Not Opened\r\n\r\n"}


I would like to remove the \r\n\r\n because I have an If Statement that changes the font color to red in a textbox if the results equals Not Opened and it is not working I believe because of the \r\n\r\n showing up.

Any ideas?
Regards,

Answer

Maybe simply remove the newlines?

txtcmdApp.Text = RunScript(@"if (Get-Process greenshot -ErrorAction silentlycontinue –ComputerName  " + txtWSName.Text + " ) {'Open'} else {'Not Opened'}")
.Replace(Environment.NewLine, "");

This will replace all new lines (that is cr+lf (\r\n) on Windows) on the string to a empty string.

Comments