Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailemVyřešeno Jak exportovat jednotlivé řádky

Á, kolega Los už mě předběhl.

Udělal jsem na to tady v poradně prográmek, když je od slova radit.
Program je pro libovolné Windows.

http://pc.poradna.net/file/view/26394-hledam-png

1) Do okénka se vloží hledaná fráze.
2) Nalistuje se velký soubor
3) Zadá se název nového souboru (který vyhovuje řádkům)





Pro pokročilejší uživatele vkládám zdroják:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BigFile
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK) // Test result.
            {
                saveFileDialog1.Title = "Navolte nazev noveho souboru, a klepnete na OK";
                if (saveFileDialog1.ShowDialog() != DialogResult.OK)
                    return;

                string saveFile = Path.GetFullPath( saveFileDialog1.FileName );
                string file = openFileDialog1.FileName;
                try
                {
                    using (StreamReader sr = new StreamReader(file, GetEncoding(file)))
                    {
                        string s = String.Empty;
                        using (StreamWriter outputFile = new StreamWriter(saveFile))
                        {
                        
                            while ((s = sr.ReadLine()) != null)
                            {
                                if (s.Contains(textBox1.Text))
                                    outputFile.WriteLine(s);
                            }
                        }
                    }

                }
                catch (IOException)
                {
                    MessageBox.Show("Chyba pri cteni souboru ci jeho zapisu");
                }
            }
            MessageBox.Show("Prace dokoncena...");
        }

        private Encoding GetEncoding(string filename)
        {
            // Read the BOM
            var bom = new byte[4];
            using (var file = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                file.Read(bom, 0, 4);
            }

            // Analyze the BOM
            if (bom[0] == 0x2b && bom[1] == 0x2f && bom[2] == 0x76) return Encoding.UTF7;
            if (bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf) return Encoding.UTF8;
            if (bom[0] == 0xff && bom[1] == 0xfe) return Encoding.Unicode; //UTF-16LE
            if (bom[0] == 0xfe && bom[1] == 0xff) return Encoding.BigEndianUnicode; //UTF-16BE
            if (bom[0] == 0 && bom[1] == 0 && bom[2] == 0xfe && bom[3] == 0xff) return Encoding.UTF32;
            return Encoding.ASCII;
        }
    }
}

Reakce na odpověď

1 Zadajte svou přezdívku:
2 Napište svou odpověď:
3 Pokud chcete dostat ban, zadejte libovolný text:

Zpět do poradny