J
Jay B. Harlow [MVP - Outlook]
Paul,
I suspect it highly depends on what you are replacing.
Regex.Replace is intended for replacing a pattern, as in a regular
expression pattern.
While StringBuilder.Replace is meant for replacing a specific string or char
(not a pattern).
Remember there is also String.Replace that is useful to replace a specific
string or char.
Generally I find its better to write "correct" programs first, then change
the code for performance later, only when that routine has proven to have
performance problems via profiling!
By "correct" I mean use Regex.Replace if you are replacing a regular
expression, other wise use StringBuilder.Replace or String.Replace based on
needing a StringBuilder or not. I would consider the StringBuilder if I had
multiple replacements on a single String. For a single replacement I would
use String.Replace.
Hope this helps
Jay
I suspect it highly depends on what you are replacing.
Regex.Replace is intended for replacing a pattern, as in a regular
expression pattern.
While StringBuilder.Replace is meant for replacing a specific string or char
(not a pattern).
Remember there is also String.Replace that is useful to replace a specific
string or char.
Generally I find its better to write "correct" programs first, then change
the code for performance later, only when that routine has proven to have
performance problems via profiling!
By "correct" I mean use Regex.Replace if you are replacing a regular
expression, other wise use StringBuilder.Replace or String.Replace based on
needing a StringBuilder or not. I would consider the StringBuilder if I had
multiple replacements on a single String. For a single replacement I would
use String.Replace.
Hope this helps
Jay