0

I am trying to join two lines in a text file and write as one line without a line feed,but the combined line is being forced to several line feeds.

What I have on original file:

[line1:abcdefghijklm CR

line2:nopqrstuvwxyz CR

CRLF]

What i need:

[output:abcdefghijklmnopqrstuvwxyz

CRLF]

What I am currently getting:

[output:abcdefghijklmnopq CRLF

rstu CRLF

vwxyz CRLF]

Line 2 gets joined to line 1 ok,but then line two gets broken into several line feeds.

I have tried replace method on ("\r","") but the output is still the same,irregardless of the text editor that i use,i.e notepad++,ultrastudio,notepad and visual studio.

Please advise,see code below,this is after reading both lines:

line2.TrimStart();
line2.Replace("\r","");
output=line1.TrimEnd+" "+line2;
filewrite.WriteLine(output);
2
Contributors
1
Reply
23
Views
2 Years
Discussion Span
Last Post by JOSheaIV
2

If I recall right the Trim function actually removes all white space (leading or trailing depending on which variation of Trim you use).

White Space includes Carriage Returns and Line Feeds

Also, how are you not getting an error with that TrimEnd written like that. Don't you need parenthesis after it?

But back on track. Try something like

output = (line1.Trim() + line2.Trim() + "\r\n"); 

(might wnat to make sure I used the right characters for CR and LF)

(Okay now I am curious how that TrimEnd isn't blowing an error, and even more has me wondering if it ties into the interesting pattern you showed above ... have to try that tonight at home)

Edited by JOSheaIV

Votes + Comments
Nice!
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.