Вопрос

I have created a "Word Merge" routine that i use personally. When I add items into my 3 text boxes, and then merge, everything looks fine. but when i copy to a clipboard, there are extra carriage returns that I didn't see before. Can anyone help? I have attached the code and two images of the results below:

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

I'm pretty sure it has to do with my delimiter splitting in the beginning, because if i just use the following, i don't have any issues:

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

Image of output results: http://screencast.com/t/zu49GgOok1m

Image of clipboard results: http://screencast.com/t/SqmJqFmqT

Это было полезно?

Решение

EDIT:

Answered in chat after playing around with it.

Requires splitting on \r and \n. Then joining back with \r and \n too.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top