I recived alarms in a form of text as the following
NE=JKHGDUWJ3 Alarm=Data Center STALZ AC Failure Occurrence=2012/4/3 22:18:19 GMT+02:00 Clearance=Details=Cabinet No.=0, Subrack No.=40, Slot No.=0, Port No.=5, Board Type=EDS, Site No.=49, Site Type=HSJYG500 GSM, Site Name=Google1 .
I need to fill it in csv file so later I can perform some analysis
I came up with this
namespace AlarmSaver
{
public partial class Form1 : Form
{
string filesName = "c:\\alarms.csv";
public Form1()
{
InitializeComponent();
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (!File.Exists(filesName))
{
string header = "NE,Alarm,Occurrence,Clearance,Details";
File.AppendAllText(filesName,header+Environment.NewLine);
}
StringBuilder sb = new StringBuilder();
string line = textBoxAlarm.Text;
int index = line.IndexOf(" ");
while (index > 0)
{
string token = line.Substring(0, index).Trim();
line = line.Remove(0, index + 2);
string[] values = token.Split('=');
if (values.Length ==2)
{
sb.Append(values[1] + ",");
}
else
{
if (values.Length % 2 == 0)
{
string v = token.Remove(0, values[0].Length + 1).Replace(',', ';');
sb.Append(v + ",");
}
else
{
sb.Append("********" + ",");
string v = token.Remove(0, values[0].Length + 1 + values[1].Length + 1).Replace(',', ';');
sb.Append(v + ",");
}
}
index = line.IndexOf(" ");
}
File.AppendAllText(filesName, sb.ToString() + Environment.NewLine);
}
}
}
the results are as I want except when I reach the part of
Details=Cabinet No.=0, Subrack No.=40, Slot No.=0,
Port No.=5, Board Type=KDL, Site No.=49, Site Type=JDKJH99 GSM, Site Name=Google1 .
I couldnt split them into seperate fields.
as the results showing is as
I want to split the details I want each element in details to be in a column
to be somthin like
its realy annoying :-)
please help , thank you in advance