Originally Posted by JonBMN
but in my case I'd like to not use a regexp which I don't think I said in my first post.
Why do people insist on not using a screwdriver to insert screws and insist on using a hammer instead.
For pattern matching (which is what your question is asking how to do) a regular expression is the appropriate tool for the job.
The only reason to not use a regular expression for this is if it is homework for a class where the teacher is handing out questions intended to tech you how to use a hammer to insert screws rather than providing questions where the answer actually needs to use the type of code that the question is supposed to be testing. But then you didn't say that this is homework so I am at a complete loss as to why you want to write many lines of inefficient code where a single statement does the job.
Helping others to solve their computer problem at http://www.felgall.com/