You are not assigning the result back to string, otherwise your both Trim
and Remove
should work.
String is an immutable type, and its method doesn't modify the exiting string, instead they return a new string. So when you do s.Remove(0, 1);
or s.Trim()
, it doesn't modify the original string, instead it returns a new string.
So for your case something like:
string newstr = s.Trim();
//OR
string newstr = s.Remove(0,1);
should work.
But remember s.Trim()
would remove any kind of white space from beginning or end of string. If that is your desired behaviour use that.
Similarly you can use string.Replace
but that will replace all occurrence of new line character from the string.
And your s.Remove(0,1)
will remove the first character irrespective of whether it is a new line character or not.