The problem is that if you find a problem in your string, you don't do anythign about it, other than tell the user.
Add a
return
to the
if
code:
c = str[i];
if (System.Char.IsSymbol(c) || System.Char.IsSeparator(c) || System.Char.IsWhiteSpace(c))
{
Console.WriteLine("Integers and identifiers can not be symbols, space or contain them");
return;
}
And it should work.
But I'd either use a
foreach
loop instead of the for:
foreach (char c in str)
{
...
}
Or use the the built in method Any (but that may be a bit advanced for you at this stage):
if (str.Any(c => char.IsSymbol(c) || char.IsSeparator(c) || char.IsWhiteSpace(c)))
{
Console.WriteLine("Integers and identifiers can not be symbols, space or contain them");
return;
}