C#:在搜索中的一个txt文件关键字 [英] C#: Searching for a keyword in a txt file
本文介绍了C#:在搜索中的一个txt文件关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题读取逗号分隔的TXT文件。这就是我要做的。我在寻找一个文本文件中的关键字,然后当我发现包含该关键字的线,让逗号分隔的关键字全行成一个字符串数组。我怎样才能做到这一点?
感谢
解决方案
就是System.IO.StreamReader文件=新就是System.IO.StreamReader(C:\\test.txt);
串线;
String []数组;
,而((行= file.ReadLine())!= NULL)
{
如果(line.Contains(MyString的))
{
数组= line.Split(,);
}
}
file.Close();
在if部分哟可以保存您的逗号分隔字符串数组
I have a problem reading a comma-delimited TXT file. This is what I am trying to do. I'm searching a text file for a keyword and then, when I've found the line containing that keyword, getting the whole line of comma-delimited keywords into a string array. How can I do this?
Thanks
解决方案
System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt");
String line;
String[] array;
while((line = file.ReadLine()) != null)
{
if (line.Contains("myString"))
{
array = line.Split(',');
}
}
file.Close();
In the if part yo can save your comma separated strings to an array
这篇关于C#:在搜索中的一个txt文件关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文