using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Parse_xml
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
openFileDialog1.Title = "File to Parse";
openFileDialog1.InitialDirectory = @"c:\";
openFileDialog1.RestoreDirectory = true;
//string dirName = System.IO.Path.GetDirectoryName(fdlg.FileName);
//MessageBox.Show(dirName);
string sFileName = openFileDialog1.FileName;
txtFileLocation.Text = sFileName;
}
private void button2_Click(object sender, EventArgs e)
{
//SaveFileDialog cock = new SaveFileDialog();
saveFileDialog1.ShowDialog();
saveFileDialog1.Title = "File to Parse";
saveFileDialog1.Filter = "Text (*.txt)|*.txt|Word Doc (*.doc)|*.doc";
string saveFileLocation = saveFileDialog1.FileName;
txtSaveLocation.Text = saveFileLocation;
}
private void button3_Click(object sender, EventArgs e)
{
string location = txtFileLocation.Text;
string Extract1 = txtExtract1.Text;
string Extract2 = txtExtract2.Text;
string EndExtract1 = Extract1;
string EndExtract2 = Extract2;
StreamReader sr = new StreamReader(location);
//listBox1.Text = sr.ReadLine();
string donger = sr.ReadToEnd();
//Search For Keywords
char[] del = new char[]
{
'<',
'>'
};
string[] SearchArray = donger.Split(del);
//MessageBox.Show(SearchArray[5]);
int ArrayLength = SearchArray.Length;
//int ArrayLength2 = ArrayLength;
int theIndex = 0;
string locationSave = txtSaveLocation.Text;
StreamWriter tw = new StreamWriter(locationSave);
while (ArrayLength > 0)
{
ArrayLength = ArrayLength - 1;
if (SearchArray[theIndex] == Extract1)
{
string schlonger = SearchArray[theIndex + 1];
string dongstar = schlonger;
if (schlonger.Length > 140)
{
//MessageBox.Show("We are in the if loop, string shortener.");
dongstar= schlonger.Substring(0, 140);
}
char[] dongChar = new char[140];
for (int i = 0; i < dongstar.Length; i++)
{
string ddd = Convert.ToString(dongstar[i]);
//dongChar[i] = dongstar[i];
}
int lengthdongChar2 = dongChar.Length;
string dongstar3 = null;
for (int i = 0; i < lengthdongChar2; i++)
{
if (dongChar[i] == '&')
{
if (dongChar[i + 1] == 'l')
{
if (dongChar[i + 2] == 't')
{
if (dongChar[i + 3] == ';')
{
dongstar3 = dongstar.Substring(0, i);
dongstar = dongstar3;
//MessageBox.Show(dongstar3 + "We are inside the dongstar");
//string dongstar2 = new string(dongChar);
}
}
}
}
}
//string shortened = schlonger.Remove(140);
lstBoxOutput.Items.Add(dongstar);
tw.WriteLine(dongstar);
}
//lstBoxOutput.Items.Add(OutputStringLine);
if (SearchArray[theIndex] == Extract2)
{
string schlonger = SearchArray[theIndex + 1];
//MessageBox.Show(schlonger);
string dongstar =schlonger;
if (schlonger.Length > 140)
{
//MessageBox.Show("We are in the if loop, string shortener.");
dongstar = schlonger.Substring(0, 140);
}
// trimming "<" from strings, below
char[] dongChar = new char[140];
for (int i = 0; i < dongstar.Length; i++)
{
string ddd = Convert.ToString(dongstar[i]);
dongChar[i] = dongstar[i];
}
string dongstar2 = null;
int lengthdongChar = dongChar.Length;
for (int i = 0; i < lengthdongChar; i++)
{
if (dongChar[i] == '&')
{
if (dongChar[i + 1] == 'l')
{
if (dongChar[i + 2] == 't')
{
if (dongChar[i + 3] == ';')
{
dongstar2 = dongstar.Substring(0, i);
dongstar = dongstar2;
//MessageBox.Show(dongstar2+"We are inside the dongstar");
//string dongstar2 = new string(dongChar);
}
}
}
}
}
//dongstar = dongstar2;
//string shortened = schlonger.Remove(140);
lstBoxOutput.Items.Add(dongstar);
tw.WriteLine(dongstar);
}
//lstBoxOutput
theIndex = theIndex + 1;
}
tw.Close();
long TheCount = CountLinesInFile(location);
string strTheCount = Convert.ToString(TheCount);
StreamReader SecondStream = new StreamReader(location);
while (TheCount > 0)
{
TheCount = TheCount - 1;
listBox1.Items.Add(SecondStream.ReadLine());
//if(sr.ReadLine=="*"+ EndExtract1 +"*")
}
//string SearchString = sr.ReadToEnd();
//MessageBox.Show(SearchArray[4]);
//MessageBox.Show(strTheCount);
//MessageBox.Show(donger);
//string str = SearchString.Trim().Split('\n');
//catch(Exception r)
// {
// MessageBox.Show(r.Message);
// }
}
static long CountLinesInFile(string f)
{
long count = 0;
using (StreamReader r = new StreamReader(f))
{
string line;
while ((line = r.ReadLine()) != null)
{
count++;
}
}
return count;
}
private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
}
}
}