/ /単語内の文字がテキストボックスを表すさまざまな文字のグループに記載されているかどうかをチェックする方法 - c#

テキストボックスを表すさまざまな文字のグループに単語の文字が記述されているかどうかをチェックする方法 - c#

ここに画像の説明を入力

私は7つのランダムにキャラクタ生成されたテキストボックス(写真の上にグループ化されています)と単語を入力するためのテキストボックス(以下にあります)があります。 今、私がこれらの言葉を入力した場合の検証です:

1)fox:少なくとも1回黄色で表示される中間語を含む必要があるため、この単語は許可しないでください

            string holdWord = textBox1.Text; //
char charToCheck = Convert.ToChar(textBox3.Text); // "a"
bool result = holdWord.Contains( charToCheck ); //false

私はこのコードを使用し、それは動作します。

2)脂肪: 上記のテキストボックスのいずれにもtが記述されておらず、この文字がそこにないことを示すエラーとしてその文字を返すべきであるため、この単語は許可しないでください)。単語は上記の7つのテキストボックス

回答:

回答№1の場合は3

だから2)あなたの唯一のオープンな要件です。

// presuming textBox1-textBox6 are the textboxes for the letters
// and textBox7 is the TextBox "Type your word"
TextBox[] textBoxes = { textBox1, textBox2, textBox3, textBox4, textBox5, textBox6 };
string wordTyped = textBox7.Text;
var notContainedLetters = wordTyped
.Where(c => !textBoxes.Any(txt => txt.Text.Contains(c)));

string notContained = String.Concat( notContainedLetters );
MessageBox.Show("These letters are in no textbox: " + notContained);

あなたは追加する必要があります using System.Linq LINQクエリの場合

あなたは使うことができます notContained.Length > 0 または Enumerable.Any 少なくとも1つの不足している文字があるかどうかを確認する:

bool anyMissing = notContainedLetters.Any();

回答№2の場合は0
        char[] originalLetters = { "F", "O", "D","J", "X"}; // Add TextBox lettes in this array
string enteredWord = "FAT"; //User Entered Word

foreach (char letter in enteredWord)
{
// check if letter can be found withinenteredWord
if (!originalLetters.Contains(letter))
{
//// Do Something
}
}