I have the good fortune to be working with Microsoft Sharepoint and extracting Web Storage System folder and document information to what I call an Intelligent Middle XML Layer to free us from the digital dashboard (not big fans), combine our Sharepoint data with SQL and Exchange, improve searching, tc. But that's another post. Amidst the cool aspects of working on this app, I encountered a stupid parsing issue that frustrated me for more than a few minutes. While this post is in the D.O.T.D. category, it was more like Stupidity Of The Day (S.O.T.D.) activity.
I needed to extract the project number from folder urls, in this example "20036969." I pass the year, assign the URL to s, and parse.

The Substring needs a starting position and length. Pretty simple. Calculating the length was my problem. The " - " string always follows the project number, so I marked its position and substracted the position of what I thought was the "start" of the number: s.IndexOf("/" + year + "/") + 6. Wrong. This subtraction yielded 16. I needed to reduce the length by the "/" + year + "/" string, so it was - 6. (I welcome a smarter calc at this length--maybe a single overloaded IndexOf()?)
I should apologize for the boring subject matter of this post: Substrings. But hey, at least I didn't write about a garbage disposal incident. A couple of morals: 1) the (parens) mark the spot. It's easy to get confused with the overloads of the IndexOf() method. Calculations happen outside of the parens or hard to decipher runtime errors will waste CPU and brain cycles, 2) starting point, length. Starting point, length, and 3) it's always the most mundane issues that kick your butt.