2 つのテキスト ボックスから 2 つの複数行の入力を取得し、それらを 2 つの配列に入れて比較する簡単なプログラムを作成しようとしています。
配列 1 のエントリ (テキスト ボックス 1 の各行は配列 1 の個別のエントリです) が配列 2 にあるかどうかを確認したい (テキスト ボックス 2 の各行は配列 2 の個別のエントリです)。
次に、結果をテキストボックスに出力します。
例えば:
配列 1「1、2、3、4、6」
配列 2「1、3、5、4」
出力する必要があります:
one = found
two = not found
three = found
four = found
six = not found
私がこれまでに持っているコードは次のとおりです。
private void button1_Click(object sender, EventArgs e)
{
textBox3.Text = "";
string[] New = textBox1.Text.Split('\n');
string[] Existing = textBox2.Text.Split('\n');
//for each line in textbox1's array
foreach (string str in New)
{
//if the string is present in textbox2's array
if (Existing.Contains(str))
{
textBox3.Text = " ##" + textBox3.Text + str + "found";
}
/if the string is not present in textbox2's array
else
{
textBox3.Text = " ##" +textBox3.Text + str + "not found";
}
}
}
いずれかのテキストボックスに複数の行がある場合、これは正しく機能しません-理由がわかりません..テスト実行で次のことが起こっています:
Array 1 - "One"
Array 2 - "One"
Result = One Found
Array 1 - "One"
Array 2 - "One, Two"
Result = One Not Found
Array 1 - "One, Two"
Array 2 - "One, Two"
Result = One found, Two Found
Array 1 - "One, Two, Three"
Array 2 - "One, Two"
Result - One Found, Two Not Found, Three Not Found
前もって感謝します