开发者

Clearing a StringBuilder Object's Current String [duplicate]

开发者 https://www.devze.com 2022-12-14 01:28 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: best way to clear contents of .NET’s StringBuilder
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

精彩评论

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

关注公众号