Stephane <(E-Mail Removed)> wrote:
> I haven't tested my application in a production environment, but I expect a
> lot of work since this is to replace about 25 smileys code in each message
> sent to my forum.
>
> By lot of work, I mean something between 10K and 20K messages posted each day.
That's not a lot of work at all.
Try running the following:
using System.Text;
using System;
public class Test
{
const int Iterations = 100000;
static void Main()
{
StringBuilder builder = new StringBuilder();
for (int i=0; i < 25; i++)
{
builder.Append ("before");
builder.Append (":-)");
builder.Append ("after");
}
string original = builder.ToString();
DateTime start = DateTime.Now;
for (int i=0; i < Iterations; i++)
{
string replaced = original.Replace (":-)", "img");
}
DateTime end = DateTime.Now;
Console.WriteLine ("{0} iterations took {1}", Iterations,
end-start);
}
}
On my laptop, it manages 100,000 iterations in about half a second.
Even if regular expressions were significantly faster, what's half a
second per day, really?
The moral is to always find out if something is actually going to be
expensive in real terms before going for a more complicated (and
potentially buggy) solution.
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too