嗨我有文本文件,我需要在C#windows应用程序中删除行 [英] Hi I have text file where I need to remove lines in C# windows applicaion

查看:66
本文介绍了嗨我有文本文件,我需要在C#windows应用程序中删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有包含大约5000行的文本文件,我需要删除几行。在提到的例子中我需要从下面删除到第2项。

这个



请在下面找到示例

Hi i have text file containing around 5000 rows where i need to remove few lines.In the example as mentioned i need to delete from below to item 2.
This

Please find example below

[item1]
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 7
[/item1]

//Remove line here in between the specific boundaries
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 8
2550 coins 995 200000 7
2550 coins 995 200000 7
//Remove line here in between the specific boundaries
[/item2]
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 7
[/item3]





我尝试了什么:



你好我有文本文件,我需要删除c#windows appl中的行icaion



What I have tried:

Hi i have text file where i need to remove lines in c# windows applicaion

推荐答案

如果你发布了一些你尝试过的例子以及为什么没有成功,问题可能会更清楚。



您是否想要删除空行?如果是这样,可以使用一种方式:



The question might be more clear if you posted some examples of what you have tried and why it hasn't succeeded.

Are you trying to remove the empty lines? If so one way would be to use:

string[] lines = File.ReadAllLines("path");

using(var writer = File.AppendText("newpath"))
{		
  foreach(var line in lines)
  {
    if(!String.IsNullOrWhiteSpace(line))
    {
      writer.WriteLine(line);
    }
  } 
}


这篇关于嗨我有文本文件,我需要在C#windows应用程序中删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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