How can we prepend strings with StringBuilder?

后端 未结 12 2291
一整个雨季
一整个雨季 2020-12-24 00:22

I know we can append strings using StringBuilder. Is there a way we can prepend strings (i.e. add strings in front of a string) using StringBuilder

12条回答
  •  一整个雨季
    2020-12-24 00:35

    Prepending a String will usually require copying everything after the insertion point back some in the backing array, so it won't be as quick as appending to the end.

    But you can do it like this in Java (in C# it's the same, but the method is called Insert):

    aStringBuilder.insert(0, "newText");
    

提交回复
热议问题