我收到了以下文本形式的警报
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 .
我需要将它填充到 csv 文件中,以便稍后我可以执行一些分析
我想出了这个
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);
结果如我所愿,除非我到达
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 .
我无法将它们分成单独的字段。
结果显示为
我想拆分详细信息我希望详细信息中的每个元素都在列中
变得像
它真的很烦人:-)
请帮忙,提前谢谢你