I have a stringbuilder that I’m manipulating several times, and I need to replace strings within it with strings of varying lengths.
sb = new StringBuilder("This has {Count} Values. Your search was '{SearchText}'. Did you mean '{DidYouMean}'?")
//get the replacement areas, this would search for the field names within {}
MatchCollection matches = GetReplacementAreas(sb);
int indexOffset=0;
foreach(Match m in matches)
{
//fields is a dictionary containing keys that match the fields
sb.ReplaceAt(m.Index,m.Length,fields[m.Value]);
}
Obviously ReplaceAt doesnt exist. I’m about to write it myself. Anybody else already done so?
1 Answer