Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
1.67/5 (2 votes)
See more:
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]


What I have tried:

Hi i have text file where i need to remove lines in c# windows applicaion
Posted
Updated 6-Mar-19 14:23pm
v2
Comments
OriginalGriff 6-Mar-19 3:46am    
You need to explain in more detail exactly what you are trying to achieve: at the moment it looks like all you want to remove ar eteh lines which say "[item1]" and "[/item1]" but you need to expand on that even if that is true. Is the text that identifies the lines always "item1"? If not, how can you tell that "item2" should not be included? What should happen to the data between the two lines?

What have you tried?
Where are you stuck?
What help do you need?

The better your question, the better the response we can give ...

1 solution

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);
    }
  } 
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900