If you need to check a set of characters, a regular expression will do the
trick more easily than looping through the characters in the string, testing
each one.
The regular expression might do it more easily, but if you don't know
regular expression syntax, the looping is easier to code. I personally have
always had a great deal of trouble relaly understanding regular expression
syntax in Unix or in .NET. But that's just me.
If you need to check a set of characters, a regular expression will do the
trick more easily than looping through the characters in the string, testing
each one.
Indeed it will - and in simple cases it may be more easily readable
too. In other cases, however, it'll be less readable as the regular
expression becomes harder to understand to the human eye. Also, using
straight code will be significantly faster, if performance is an issue.
(Performance should only be taken into consideration when it's actually
proved to be problematic.)
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.