我们如何在StringBuilder之前添加字符串? [英] How can we prepend strings with StringBuilder?

查看:132
本文介绍了我们如何在StringBuilder之前添加字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们可以使用 StringBuilder 附加字符串.有没有一种方法可以使用 StringBuilder 前缀字符串(即在字符串前面添加字符串),以便我们可以保持 StringBuilder 提供的性能优势?

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 so we can keep the performance benefits that StringBuilder offers?

推荐答案

使用将位置参数设置为0的insert方法与前置(即在开头插入)相同.

Using the insert method with the position parameter set to 0 would be the same as prepending (i.e. inserting at the beginning).

示例为: varStringBuilder.Insert(0,"someThing");

它同时适用于 C# 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆