私はC#を初めて使用しています。文字列"code:A1"
を検索すると、"code:A14"
という行も表示されます。正確な単語"code:A1"
を検索するか、コードから"code:A14"
を禁止するだけです。ここで私がやったことはうまくいきません:正確な文字列を検索するか、文字列を含む行をスキップします。
try
{
using (System.IO.StreamReader file = new System.IO.StreamReader(@"<path to file>"))
{
string motcletest = "code:A1";
string motcle = "code:A16";
string motcledm = "code:A14";
string line;
line = file.ReadLine();
do
{
if (line.Contains(motcletest) || line.Contains(motcle))
{
SetupV02_textbox.Text = line;
}
if (line.Contains(motcledm))
{
continue;
}
}
while ((line = file.ReadLine()) != null);
//string retval = SetupV02_textbox.Text.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).First(p => p.Equals(motcle));
string setup = SetupV02_textbox.Text;
string testomada2 = setup.Split(new string[] { "code:" }, StringSplitOptions.None).Last();
label2.Text = testomada2.ToString();
}
}
私のためにうまくその仕事に答えるためのty –