-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
115 lines (93 loc) · 3.86 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Windows.Forms;
namespace ParseFileForDataProcessing
{
public partial class Form1 : Form
{
string gbl_save_filename = "";
string gbl_open_filename = "";
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
using (SaveFileDialog Dialog = new SaveFileDialog())
{
if (Dialog.ShowDialog() == DialogResult.OK)
gbl_save_filename = Dialog.FileName;
else
return;
}
using (OpenFileDialog Dialog = new OpenFileDialog())
{
if (Dialog.ShowDialog() == DialogResult.OK)
gbl_open_filename = Dialog.FileName;
else
return;
}
checkBox1.Font = new Font(checkBox1.Font, FontStyle.Regular);
checkBox1.Checked = false;
#region parsing
try
{
// using (StreamWriter outfile2 = new StreamWriter(gbl_save_filename + "1"))
// {
using (StreamWriter outfile = new StreamWriter(gbl_save_filename))
{
using (StreamReader infile = new StreamReader(gbl_open_filename))
{
String line;
int count = 0;
//Read the first line of text
line = infile.ReadLine();
//Continue to read until you reach end of file
while (line != null)
{
#region cr_sr_RB
if (cr_sr_RB.Checked == true)
{
line = line.Replace(header_TB.Text, null);
string[] a = line.Split(textBox2.Text.ToCharArray());
if ((a.Length == data_fields_NUD.Value))// && (test == true))
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data_fields_NUD.Value; i++)
{
Double n;
bool isNumeric = Double.TryParse((a[i].TrimStart()).TrimEnd(), out n);
if (isNumeric)
{
sb.Append((a[i].TrimStart()).TrimEnd());
sb.Append(" ");
}
}
string myString = sb.ToString().TrimEnd();
outfile.WriteLine(myString);
}
}
#endregion
count++;
line = infile.ReadLine();
}
checkBox1.Font = new Font(checkBox1.Font, FontStyle.Bold);
checkBox1.Checked = true;
}
}
// }
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
#endregion
}
}
}