C # The problem of trimming rows in rows

I have a row that populates from a datagrid Xceed, as such:

study = row.Cells["STUDY_NAME"].Value.ToString().TrimEnd (Environment.NewLine.ToCharArray()); 

However, when I pass the research line to another part of the program, it gives an error, because the line is still displayed as: "PI3K1003 \ n"

I also tried:

 TrimEnd('\r', '\n'); 

Does anyone have any ideas?

Thanks.

+4
source share
3 answers
 TrimEnd('\r', '\n'); 

does not work because you have a space at the end of this line, use

 TrimEnd('\r', '\n', ' '); 
+6
source

The problem with this line is that in the end you don't have \n . You have a ' ' (empty) at the end, and therefore \n not clipped.

So, I would try TrimEnd( ' ', '\n', '\r' );

+5
source

Use a replacement instead of TrimEnd, in this case you never encounter the problem of "space problems";)

  string val = @"PI3K1003\n"; val = val.Replace(@"\n", String.Empty).Replace(@"\r", String.Empty); 

But TrimEnd is always a solution:

 TrimEnd('\r', '\n', ' ') 
0
source

Source: https://habr.com/ru/post/1344090/


All Articles