我创建了一个我个人使用的“Word Merge”例程。当我将项目添加到我的 3 个文本框中,然后合并时,一切看起来都很好。但是当我复制到剪贴板时,会出现我以前没有看到的额外回车符。任何人都可以帮忙吗?我附上了下面的代码和两个结果图像:
private void button25_Click(object sender, EventArgs e)
{
char[] delimiterChars2 = { ',', ':', '|', '\n' };
List<string> listBox1 = new List<string>(textBox_MergeList1.Text.Split(delimiterChars2));
List<string> listBox2 = new List<string>(textBox_MergeList2.Text.Split(delimiterChars2));
List<string> listBox3 = new List<string>(textBox_MergeList3.Text.Split(delimiterChars2));
string outputDelimiter = "-";
var result = from s1 in listBox1
from s2 in listBox2
from s3 in listBox3
select s1 + outputDelimiter + s2 + outputDelimiter + s3;
foreach (var item in result)
{
textBox_MergeListResults.Text = String.Join("\r\n", result);
}
Clipboard.SetText(textBox_MergeListResults.Text);
}
我很确定这与我一开始的分隔符拆分有关,因为如果我只使用以下内容,我没有任何问题:
List<string> listBox1 = new List<string>() { "A", "B", "C" };
List<string> listBox2 = new List<string>() { "1", "2", "3" };
List<string> listBox3 = new List<string>() { "Dogs", "Cats", "Pigs" };