You might be better off using parser generator tool http://www.antlr.org is a good one. You can look at couple of my examples: http://www.codeproject.com/csharp/stringtokenizer.asp[^] or have a look at http://www.adersoftware.com/index.cfm?page=templateEngine2[^] (library with easy to use hand coded lexer/parser) or http://www.adersoftware.com/index.cfm?page=compilers[^]