我有一个txt文件,其中列出了姓名,日期和性别,如下所示。我需要找到一个子字符串并显示txt文件中具有特定值的行,例如(“ m”)。有人可以帮我修复我的代码吗
(我的txt文件的外观示例) 1.乔什,21,m 2.麦克,09,m 3. emily,08,f
using (StreamReader sr = new StreamReader("Games.txt"))
{
ListBoxGames.Items.Clear();
while ((line = sr.ReadLine()) != null)
{
str = line.Trim().Split(" , ");
String test = chargames.ToString();
for (int i = 0; i < str.Length; i++)
{
if (radioBtnPC.Checked == true)
{
if (str.Contains("NS"))
{
bolShownGames = true;
ListBoxGames.Items.Add(line);
}
}
如果您可以使用Nuget包,并且可以为您提供一种简单的方法,请执行以下操作:
努吉特:
DataJuggler.Core.UltimateHelper(.Net框架)
DataJuggler.UltimateHelper.Core(点网核心)
获取行号方法:
然后调用它:
Full Source Code Is Here: https://github.com/DataJuggler/UltimateHelper