Thanks for your post, but i solved the problem with RegularExpressions, see
below:
Fair enough; whatever works and is easy for you to maintain.
For the record, the regex will be slower, but it is unlikely that this
is significant (unless you are doing some serious data processing);
but some metrics from a performance test rig:
StringBuilder: 234ms; chk=9500000
Regex (compiled): 1580ms; chk=9500000
Regex (new): 21848ms; chk=9500000
(500k iterations, release mode, console, no debugger, etc) - so the
regex via "new" each time is 100 times slower. If you want to use
regex, I recommend pre-compiling it so that it is only 7 times slower:
const string PATTERN = @"([A-Fa-f0-9]{4})([A-Fa-f0-9]{4})([A-Fa-
f0-9]{4})([A-Fa-f0-9]{4})";
static readonly Regex regex = new Regex(PATTERN,
RegexOptions.Compiled);
static string Format2(string value)
{
return regex.Replace(value, "$1-$2-$3-$4");
}
Marc