Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading from a file in C# without the newline character

Tags:

c#

file

i want to read from a text file in C#. But I want all the lines in the file to be concatenated into one line.

for example if i have in the file as

ABCD

EFGH

I need to read ABCDEFGH as one line.

I can do this by reading one line at a time from the file and concatenating that line to a string in a loop. But are there any faster method to do this?

like image 272
P basak Avatar asked Sep 18 '25 09:09

P basak


1 Answers

string.Join(" ", File.ReadAllLines("path"));

Replace " " with "" or any other alternative "line-separator"

Example file:

some line

some other line

and yet another one

With " " as separator: some line some other line and yet another one

With "" as separator: some linesome other lineand yet another one

like image 191
SimpleVar Avatar answered Sep 20 '25 22:09

SimpleVar