Given two files:
File1
a a a
b b b
c c c
File2
d d
e e
Bash has a command that will horizontally concatenate these files:
paste File1 File2
a a a d d
b b b e e
c c c
Does C# have a built-in function that behaves like this?
public void ConcatStreams(TextReader left, TextReader right, TextWriter output, string separator = " ")
{
while (true)
{
string leftLine = left.ReadLine();
string rightLine = right.ReadLine();
if (leftLine == null && rightLine == null)
return;
output.Write((leftLine ?? ""));
output.Write(separator);
output.WriteLine((rightLine ?? ""));
}
}
Example use:
StringReader a = new StringReader(@"a a a
b b b
c c c";
StringReader b = new StringReader(@"d d
e e";
StringWriter c = new StringWriter();
ConcatStreams(a, b, c);
Console.WriteLine(c.ToString());
// a a a d d
// b b b e e
// c c c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With