gpt4 book ai didi

c# - 是否有用于水平字符串连接的内置函数?

转载 作者:太空狗 更新时间:2023-10-29 19:45:10 24 4
gpt4 key购买 nike

给定两个文件:

文件 1

a a a
b b b
c c c

文件2

d d
e e

Bash 有一个命令可以水平连接这些文件:

paste File1 File2

a a a d d
b b b e e
c c c

C# 有这样的内置函数吗?

最佳答案

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 ?? ""));
}
}

使用示例:

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

关于c# - 是否有用于水平字符串连接的内置函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32122433/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com