Re: Search for multiple things in a string
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Wed, 14 Sep 2005 22:51:10 +0100
Oliver Sturm <oliver@xxxxxxxxxxxx> wrote:
> >Until, of course, something1 etc start having characters in which need
> >escaping - how confident would you be that you'd get that right? It's
> >an extra thing to think about - and I'm sure the real strings aren't
> >actually "something1" etc.
>
> Aren't you exaggerating a bit here? There are regex testers out there to
> help you with building regular expressions and the Regex class itself
> knows how to escape special chars - it's not that big a deal.
No, but it's still harder to remember than not having to remember
anything special at all, which is what you get with IndexOf.
In a hurry, I can very easily see someone changing a string literal
from one thing to another, not noticing that as it's a regular
expression, they need to escape part of their new string.
Now, where's the *advantage* of using regular expressions in this case?
> >Well, I don't have to learn (or more importantly, remember) any extra
> >bits of language other than C# (which I already need to know) to get it
> >right with IndexOf, even if the strings I'm looking for contain things
> >like dots, stars etc. That isn't true for regular expressions.
>
> No, it isn't. But you won't get far in today's programming world if you
> don't know the first thing about SQL or XML, for example, so I guess
> you're not suggesting that one language is enough?
No - but I'm suggesting that when one language works perfectly well for
the task at hand, and it's the same language that the rest of your code
is written in, it's easier to stick within that language.
> I believe that Regular Expressions are a powerful technology well
> worth learning - and it's probably good advice to stay clear of them
> for anything but the simplest applications if you're not willing to
> put in a bit of time to get to know them.
Regular expressions are absolutely worth learning for where they
provide extra value. In cases like this, where they're only really
providing extra things to remember (what you need to escape, or to call
Regex's own escaping mechanism) I don't think there's any value.
> About IndexOf, as I meant to say already, as long as the problems you're
> trying to solve are the kind that can be solved with those simple string
> functions (and without resulting in huge algorithms), you'll probably have
> the performance argument on your side anyway.
Well, I'm much keener on the readability argument than the performance
one - I suspect that the performance difference would rarely be of
overall significance.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: Search for multiple things in a string
- From: Oliver Sturm
- Re: Search for multiple things in a string
- References:
- Search for multiple things in a string
- From: tshad
- Re: Search for multiple things in a string
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Search for multiple things in a string
- From: tshad
- Re: Search for multiple things in a string
- From: Jon Skeet [C# MVP]
- Re: Search for multiple things in a string
- From: Oliver Sturm
- Search for multiple things in a string
- Prev by Date: Re: multi-threading problem...help
- Next by Date: project level scope declaration in C#
- Previous by thread: Re: Search for multiple things in a string
- Next by thread: Re: Search for multiple things in a string
- Index(es):
Relevant Pages
|
Loading