Hi all,
I am working on re-writing an existing Java software solution in .NET. At one point, the Java solution reads a time stamp at the beginning of a string, simply like this:
SimpleDateFormat dateFormat = new SimpleDateFormat(timeFormat);
dateFormat.setLenient(false);
try
{
timeStamp = dateFormat.parse(line);
}
catch (ParseException e)
{
//...
}
Now I am trying to do the same in C#:
DateTimeFormatInfo dateTimeFormatInfo = new DateTimeFormatInfo();
dateTimeFormatInfo.FullDateTimePattern = format;
try
{
timeStamp = DateTime.Parse(line, dateTimeFormatInfo);
}
catch (FormatException ex)
{
//...
}
Both languages work until I add some random text after the time stamp in the line variable. Java will just ignore it, but C# will not allow anything else after the time stamp text in the line.
So while Java is happy to parse "01/01/01 01:01:01,001 Hello World!" as a time stamp, C# is not, because " Hello World!" is not specified in the format string.
However, as I cannot make any statement about what might come after the time stamp inside my strings, I cannot include it in my format string.
Any ideas?
Thank you in advance.