This is my situation, I was able to remove the spaces using trim or replace. But it does not remove the linefeed or newline at the end of each file. How can I remove the spaces and linefeed in C#?
Thanks in advance.
This is my situation, I was able to remove the spaces using trim or replace. But it does not remove the linefeed or newline at the end of each file. How can I remove the spaces and linefeed in C#?
Thanks in advance.
You can call Trim method with all characters that you want to be removed like:
line = line.Trim(' ','\r','\n');
myString = myString.Replace(System.Environment.NewLine, string.Empty)
myString = myString.Replace(" ", string.Empty);
Alternately, use:
string replacement = Regex.Replace(s, @" |\t|\n|\r", string.Empty);
For Line Feeds and New Lines:
myString = myString.Replace(System.Environment.NewLine, "replacement text")
For Spaces:
myString = myString.Replace(" ", "replacement text");
Reference: