-2
我是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 for your ur for its fine fine for me –