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
.
views:
94answers:
1
+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
2010-08-02 15:07:38
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
2010-08-02 15:23:50
@Mark: No worries. And yeah, the debugger isn't *always* perfect - especially if you're running it on an optimised assembly.
Noldorin
2010-08-02 15:25:48
Thanks. What is the "Cleanup" badge I just earned?
Mark Richman
2010-08-02 15:33:28
@Mark Richman: You got it because you rolled-back changes to your question.
Noldorin
2010-08-02 15:41:00