作者:素材火 | 来源:互联网 | 2023-09-15 13:44
Ihaveatxtfilecontains:我有一个txt文件包含:##testthisisatest127.0.0.1test69.com127.0.0.1
I have a txt file contains:
我有一个txt文件包含:
#
#test
this is a test
127.0.0.1 test69.com
127.0.0.1 http://test69.com
127.0.0.1 www.test69.com
127.0.0.1 man.test
127.0.0.1 http://man.test
127.0.0.1 www.man.test
127.0.0.1 www.another.test
How can I load all the lines in to a listbox but just keep only 3 lines in listbox like :
如何将所有行加载到列表框中,但只在列表框中保留3行,如:
test69.com
man.test
another.test
Example: My code works well but I can't avoid that my listbox loaded www.test69.com
and http://test69.com
but I don't want them, I just want something like test69.com
appears
示例:我的代码运行良好,但我无法避免我的列表框加载www.test69.com和http://test69.com但我不想要它们,我只想要像test69.com这样的东西出现
string str = "";
StreamReader sr = new StreamReader("C:\\Users\\GhoSter\\Desktop\\test.txt");
while ((str = sr.ReadLine()) != null)
{
if (Check(str) == true)
{
string localip = str.Substring(0,9);
string load = str.Replace(localip + " ", "");
myList.Add(load);
}
}
this.listBox1.DataSource = myList;
}
bool Check(string s)
{
bool flag = false;
if (s == "" || s == null)
flag = false;
else
{
string first = s.Substring(0, 1);
switch (first)
{
case "0":
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
flag = true;
break;
default:
flag = false;
break;
}
}
return flag;
}
4 个解决方案