You'd think there would be an intuitive way to do this, but....
A solution I found suggests the following:
// make a StringWriter, and fill it with junkStringWriter sw = new StringWriter();sw.Write("Don't want to see this");// and HERE IS THE MAGICStringBuilder sb = sw.GetStringBuilder();sb.Remove(0, sb.Length);// your StringWriter is now empty!
This worked for me (in the same situation as you -- using an XmlTextWriter
that dumps to the StringWriter
).
Perhaps somebody has an intuitive answer for why nothing like this is built-in.