如果行以特定的单词或数字开头,我如何读取文件 [英] How I Read File If Line Starts With Specific Words Or Numbers

查看:74
本文介绍了如果行以特定的单词或数字开头,我如何读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



有人可以帮帮我。如果文件包含特定单词或数字的开头,我将读取文件。

如果文件以数字开头和结尾,则READ FILE或不读取文件。





我的代码:

 私有  void  button1_Click( object  sender,EventArgs e)
{
// * Openfiledialog

OpenFileDialog = new OpenFileDialog();
of.ShowDialog();
textBox1.Text = of.FileName;
}





这里是打开文件对话框的代码,我在条形图下面有一个文本框来读取文件。

解决方案

你可以通过使用以下语句来实现这一点



 File.ReadLines (file.txt)。First()。StartsWith(); 



 File.ReadLines(file.txt)。Last( ).EndsWith(); 





ReadLines()的优点是它不会将整个文件加载到内存中。


使用 TextReader [ ^ ]。

Hi!

can someone help me. I will Read a File if the file contains starts with specific word or numbers.
If the file starts and ends with the numbers, READ FILE or not not read the file.


my code:

private void button1_Click(object sender, EventArgs e)
        {
            //*Openfiledialog

            OpenFileDialog of = new OpenFileDialog();
            of.ShowDialog();
            textBox1.Text = of.FileName;
        }



here are the code to open file dialog and i have a textbox under the bar to read the file.

解决方案

You could achieve this by using the following statements

File.ReadLines("file.txt").First().StartsWith();


File.ReadLines("file.txt").Last().EndsWith();



The advantage of ReadLines() is that it will not load the whole file into memory.


Use a TextReader[^].


这篇关于如果行以特定的单词或数字开头,我如何读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆