Tavakkoli
Tavakkoli

Reputation: 97

How to split merged file by file header?

i have big file with content of merged some other file.
every file have a strings in start of himself
in this code i can catch the index of header

private void button1_Click(object sender, EventArgs e)
{
    string s = File.ReadAllText("D:\\test.img");

    int i = 0;
    while ((i = s.IndexOf("xxxyyyzzz", i)) != -1)
    {
        listBox1.Items.Add(i);
        i++;
    }
}

how can split this file with header string ?

Upvotes: 0

Views: 38

Answers (1)

Kelso Sharp
Kelso Sharp

Reputation: 972

Doesn't get any simpler than this.

private void button1_Click(object sender, EventArgs e)
{
   string s = File.ReadAllText("D:\\test.img");
   var array = s.split("xxxyyyzzz", StringSplitOptions.None);

   forEach(string s in array)
   {
       listBox1.Items.Add(s);
   }
}

Upvotes: 1

Related Questions