开发者

Clearing a StringBuilder Object's Current String [duplicate]

This question already has answers here: Closed 12 years ago.

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜