The real simplest way to do this is to use regular expressions, not gobs of split and indexof operations.
Regular expressions allow you to specify a pattern out of which pieces of a string can be extracted in a straightforward fashion. If the format changes, or there is some subtlety not initially accounted for, you can fix the problem by adjusting the expression, rather than rewriting a bunch of code.
Here’s some documentation for regular expressions in .NET: http://msdn.microsoft.com/en-us/library/az24scfc.aspx
This is some sample code that’ll probably do what you want. You may need to tweak a little to get the desired results.
var m = Regex.Match(currentLine, @"^\[(?<date>[^\]]*)\]\s+(?<int>[0-9]+)\s+(?<message>.*)\s*$");
if(m.Success) {
// may need to do something fancier to parse the date, but that's an exercise for the reader
var myDate = DateTime.Parse(m.Groups["date"].Value);
var myInt = int.Parse(m.Groups["int"].Value);
var myMessage = m.Groups["message"].Value;
}
2
solved Simple Double Split [duplicate]