Here is the problem. I am working on a project in WPF and C# with 4.0 .net platform. I have a string which i got from a textbox with Accepts return = “true”. The string is as follows
string P = @"Copyright 1995-2010 BYTES.
All rights Reserved.
Formerly "TheScripts.com" from 2005-2008";
Now i want to detect when the carriage return character is encountered. So that i can cut the string short to just “Copyright 1995-2010 BYTES.” and remove all the characters after carriage return is encountered.
I tried doing this
string ip = datarow[0].ToString();
string trimed= ip.TrimEnd(new char[] {'\r','\n'});
profileFNcb.Items.Add(trimed);
NOT WORKING PLEASE HELP GUYS
Use
string.SplitwithEnvironment.NewLinein order to split the string on line breaks:This results in a string array containing each line.
To get the first line, assuming the returned
string[]is in alinesvariable:The reasons your solution is not working – the
TrimEndonly removes the characters from the end of the string, not the middle.