*/* Hello every one.

  • I am Syd M M H M .
  • Egyptian Engineer
  • This is a short Progrm code By c# for reading text file and select a sub line that contains a certain characters( as "38", "-" or "38-") Then adding these lines to a textbox in user form to be read and processed by users */
  • Created by SharpDevelop.
  • User: wp_Egypt ENG. SYED MMHM
  • To change this template use Tools | Options | Coding | Edit Standard Headers.
  • using System;
  • using System.Collections;
  • using System.IO;
  • using System.Windows.Forms;
  • namespace CONSOLE
  • {
  • class Program
  • {
  • public static void Main(string[] args)
  • {
  • string writepath= AppDomain.CurrentDomain.BaseDirectory +"READDATA.TXT";
  • string fileName= AppDomain.CurrentDomain.BaseDirectory;
  • var lines = File.ReadAllLines(fileName + "B18all00.TXT");
  • Console.WriteLine(lines.Length.ToString());
  • //
  • int COUNTER=0;
  • int d=0;
  • ArrayList ar =new ArrayList();
  • string subline="";
  • using (System.IO.StreamWriter file = new System.IO.StreamWriter(writepath)) {
  • for(int j=9;j< lines.Length; j++) {
  • // foreach (string *line in lines)
  • // {
  • subline= lines[j].ToString().Substring(16,16);
  • if (subline.Contains("38"))
  • { file.WriteLine(lines[j].ToString());}
  • }
  • else if(subline.Contains("-") COUNTER++;
  • else if(subline.Contains("38-") || subline.Contains("-38"))
  • d++;
  • else
  • COUNTER+=0;
  • } Console.WriteLine(COUNTER.ToString()); Console.WriteLine(d.ToString());
  • }
  • Console.ReadKey(true);
  • }
  • }
  • }
  • ============================================================================================================================
  • /*
  • * Created by SharpDevelop.
  • * User: Eng. SAYED M M HASANEIN(WP_Egypt)
  • * Date: 12/1/2018
  • * Time: 2:24 PM
  • *
  • * To change this template use Tools | Options | Coding | Edit Standard Headers.
  • */
  • using System;
  • using System.Collections;
  • using System.Collections.Generic;
  • using System.Drawing;
  • using System.IO;
  • using System.Threading;
  • using System.Windows.Forms;
  • namespace ZONE38HF
  • {
  • /// <summary>
  • /// Description of MainForm.
  • /// </summary>
  • public partial class MainForm : Form
  • {
  • public MainForm()
  • {
  • //
  • // The InitializeComponent() call is required for Windows Forms designer support.
  • //
  • InitializeComponent();
  • //
  • // TODO: Add constructor code after the InitializeComponent() call.
  • //
  • }
  • void Button1Click(object sender, System.EventArgs e)
  • {
  • try
  • {
  • int i =0,count=0,No_oflines=0;
  • ArrayList ar1= Class1.get_no_oflines();
  • No_oflines= int.Parse(ar1[0].ToString());
  • // FileDialog dialog= new OpenFileDialog();
  • // dialog.Title= "CHOOSE TEXT FILE TO READ DATA";
  • // dialog.ShowDialog();
  • String path = ar1[1].ToString(); //dialog.FileName;
  • // AppDomain.CurrentDomain.BaseDirectory + "vvv.text";
  • FileStream stream= new FileStream(path,FileMode.Open,FileAccess.ReadWrite);
  • // No_oflines= int.Parse(txtNooflines.Text);
  • using (TextReader textReader = new StreamReader(stream))
  • {
  • string line = "";
  • string zone="";
  • // int c1=0;
  • //
  • while( i<No_oflines)
  • {
  • try
  • {
  • line= textReader.ReadLine();
  • if(i <8)
  • {
  • textBox1.AppendText(line + Environment.NewLine);
  • count++;
  • }
  • else
  • {
  • zone= line.Substring(16,31);
  • if(zone.Contains("38") || zone.Contains("37-39")
  • || zone.Contains("1-85"))
  • {
  • textBox1.AppendText(line + Environment.NewLine);
  • count++;
  • }
  • }
  • }
  • catch(Exception ec )
  • {
  • MessageBox.Show("Message " + ec.Message
  • + "stack trace :" + ec.StackTrace);
  • }
  • i++;
  • }
  • textBox1.AppendText( "Found Number of lines = "+ count.ToString());
  • }
  • }
  • catch (Exception e1)
  • {
  • MessageBox.Show(e1.Message, "Error Processing zone 38 file: " );
  • }
  • try
  • {
  • SaveFileDialog save= new SaveFileDialog() ;
  • save.Filter= "*.txt|*.*";
  • save.ShowDialog();
  • MessageBox.Show(save.FileName);
  • save.Title= "Write FILE NAME TEXT TO SAVE YOUR ZONE DATA";
  • File.WriteAllText(save.FileName,DateTime.Now.ToString()+" "+ Environment.NewLine + textBox1.Text);
  • }
  • catch(Exception e2)
  • {
  • MessageBox.Show(e2.Message, "Error saving zone 38 file: ");
  • }
  • textBox1.WordWrap= false;
  • this.BackColor=Color.DarkGreen;
  • Thread.Sleep(1000);
  • textBox1.BackColor= Color.YellowGreen;
  • }
  • // public static int get_no_oflines()
  • // {
  • //
  • // int co = 0;
  • // FileDialog dialog= new OpenFileDialog();
  • // dialog.Title= "CHOOSE TEXT FILE TO READ DATA";
  • // dialog.ShowDialog();
  • // String path = dialog.FileName;
  • // StreamReader sr = new StreamReader(path); // @"C:\Users\WP.DEPT\Desktop\B20all00.txt");
  • // //Single line from fileIO.txt
  • // String strLine;
  • // //Continues to output one line at a time until end of file(EOF) is reached
  • // while ((strLine = sr.ReadLine()) != null)
  • // {
  • // Console.WriteLine(strLine);
  • // co++;
  • // }
  • // //Cleanup
  • // sr.Close();
  • // return co;
  • // }
  • void Button2Click(object sender, EventArgs e)
  • {
  • MessageBox.Show(Class1.get_no_oflines().ToString());
  • }
  • void TxtNooflinesTextChanged(object sender, EventArgs e)
  • {
  • }
  • }
  • }

https://sayedmmh.blogspot.com/