Possible Duplicate:
Regex replacements inside a StringBuilder
What is the best way to do a Regex Replace, many times, on StringBuilder?
If you don't mind NOT being a tl;dr
person, read further for details:
Hi, I have a function that does quite a lot of string manipulations on a string. So naturally, I am using StringBuilder class for it. Now I am in quite a dilemma.
My function is something like this:
ParsedText.Append("some footers here");
ParsedText.Replace("[b]","<b>"); //format all bold opens
ParsedText.Replace("[/b]","</b>"); //format all bold closes
ParsedText.Replace("\n","<br />"); //format newlines
.... sh!* load of other replaces and manipulations ...
//Add <a href> to all links
ParsedText = new StringBuilder(Regex.Replace(ParsedText, "pattern", "replacement"))
And now, I have a.. custom list of words (patterns) that I would want to replace - about 20 patterns..
I am trying to replace all smiley symbols with their respective images; like so:
:) becomes <img src="smile.png" />
;) becomes <img src="wink.png" />
and etc...I have about 20 images / symbols to replace and I am using this regex
(?<=^|\s):d(?=$|\s) //positive lookahead and lookback at :d
which Bob Vale kindly provided.
All this is great, except, I don't know how to regex replace with StringBuilder and I don't want to create a new StringBuilder like so:
ParsedText = new StringBuilder(Regex.Replace(...));
twenty times as I think it defeats the whole memory conservation purpose.
So, What is the best way to do a Regex Replace on StringBuilder?
Thanks!