Clearing a StringBuilder Object's Current String [duplicate]
Possible Duplicate:
best way to clear contents of .NET’s StringBuilder
Is there a quick and easy way to get rid of what a StringBuilder currently holds?
I was looking for a Clear() method but I can't fi开发者_JS百科nd it. ;)
I would to do
stringBuilderObject = ""
or something along those lines.
This will do it
stringBuilderObject.Length = 0;
stringBuilderObject.Remove(0, stringBuilderObject.Length)
stringBuilderObject = new StringBuilder(); // Let the GC do its job
This should do it ;)
myStringBuilder = new StringBuilder();
stringBuilderObject.Remove(0,stringBuilderObject.Length)
精彩评论