tags:

views:

94

answers:

1

Why would myString.Contains(" ") or myString.IndexOf(' ') throw a FormatException "Invalid name format"? This exception is only thrown when there is a space in myString.

+9  A: 

Looking at the MSDN pages for the string.Contains and string.IndexOf methods clearly shows that neither of these methods ever throws a FormatException.

I can only conclude that it must be another part of the code (possibly a call to string.Format?) throwing this exception. Perhaps posting the relevant section of code would help?

Noldorin
Sorry, this was my mistake. I don't know why, but the debugger caught the exception on the wrong line of code:if (!Regex.IsMatch(playerName, @"^[a-zA-Z'.\s]{1,255}$")) throw new FormatException("Invalid name format");
Mark Richman
@Mark: No worries. And yeah, the debugger isn't *always* perfect - especially if you're running it on an optimised assembly.
Noldorin
Thanks. What is the "Cleanup" badge I just earned?
Mark Richman
@Mark Richman: You got it because you rolled-back changes to your question.
Noldorin