Debug formatting code
Posted
by Arcadian
on Stack Overflow
See other posts from Stack Overflow
or by Arcadian
Published on 2010-06-09T19:37:41Z
Indexed on
2010/06/09
19:42 UTC
Read the original article
Hit count: 252
I'm trying to debug my code here:
private void CheckFormatting()
{
StringReader objReaderf = new StringReader(txtInput.Text);
List<String> formatTextList = new List<String>();
do
{
formatTextList.Add(objReaderf.ReadLine());
}
while (objReaderf.Peek() != -1);
objReaderf.Close();
for (int i = 0; i < formatTextList.Count; i++)
{
if (!Regex.IsMatch(formatTextList[i],
"G[0-9]{2}:[0-9]{2}:[0-9]{2}:[0-9]{2} JG[0-9]{2"))
{
MessageBox.Show("Line " + formatTextList[i] + " is not formatted correctly.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
}
else
{
this.WriteToFile();
MessageBox.Show("Your entries have been saved.", "Saved",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
what it is supposed to do is to check each line in the list. if one of them isn't formatted correctly, then break the loop and display a message box, if all the lines are formatted properly then it should call the WriteToFile method. However, when testing it using input that WAS correctly formatted it displayed the error message and broke the loop. Anyone figure out why? There's some rep points in it for you :)
Thanks in advance
© Stack Overflow or respective owner