StringBuilder capacity()

前端 未结 8 1113
轮回少年
轮回少年 2020-12-01 14:47

I noticed that the capacity method returns StringBuilder capacity without a logic way ... sometime its value is equals to the string length other t

8条回答
  •  囚心锁ツ
    2020-12-01 15:09

    EDIT: Apologies - the below is information on .NET's StringBuilder, and is not strictly relevant to the original question.

    http://johnnycoder.com/blog/2009/01/05/stringbuilder-required-capacity-algorithm/

    StringBuilder allocates space for substrings you might add to it (much like List creates space the array it wraps). If you want the actual length of the string, use StringBuilder.Length.

提交回复
热议问题