Esempio n. 1
0
        public void Parse()
        {
            Segment data = null;
            IList<Segment> datas = new List<Segment>();
            int index = 1;

            try
            {
                FileStream fs = new FileStream(this.src, FileMode.Open, FileAccess.Read);

                using (StreamReader sr = new StreamReader(fs))
                {
                    string line = sr.ReadLine().Trim();

                    while (line != "*END*")
                    {
                        if (!string.IsNullOrEmpty(line))
                        {
                            if (line.StartsWith(this.prefix))
                            {
                                if (data != null)
                                {
                                    datas.Add(data);

                                    SaveToFile(data);

                                    //Console.WriteLine("生成[" + data.ID + "]完成。");

                                    index++;
                                }

                                data = new Segment();

                                //int preLength = this.prefix.Length;
                                string title = line.Substring(this.preCount).Trim();
                                data.Title = title;
                                data.ID = index.ToString("D3"); //输出001
                            }
                            else
                            {
                                string content = line.Trim();

                                if (!string.IsNullOrEmpty(content))
                                {
                                    data.Content += content + "\n";
                                }
                            }
                        }

                        line = sr.ReadLine().Trim();
                    }

                    // Save the last
                    SaveToFile(data);

                    // Save the category
                    datas.Add(data);
                    SaveToCategory(datas);
                    //Console.WriteLine("生成[" + "目录" + "]完成。");
                }
            }
            catch (System.Exception ex)
            {
            }
        }
Esempio n. 2
0
        private void SaveToFile(Segment data)
        {
            string saveTo = this.target + data.ID + ".txt";

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(saveTo))
            {
                file.WriteLine(data.Title);
                file.WriteLine(data.Content);
                file.WriteLine("[好阅, http://okr.me]");
            }
        }