Java 和 C# 中 StringBuilder 的区别 [英] differences between StringBuilder in Java and C#

查看:40
本文介绍了Java 和 C# 中 StringBuilder 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Java 代码转换为 C#.Java 中的 StringBuilder 类似乎比 C# 类拥有更多的方法.我对(比如说)Java 功能感兴趣

I am converting Java code to C#. The StringBuilder class in Java seems to have many more methods than the C# one. I am interested in (say) the Java functionality

sb.indexOf(s);
sb.charAt(i);
sb.deleteCharAt(i);

这在 C# 中似乎没有.

which seems to be missing in C#.

我想前两个可以由

sb.ToString().IndexOf(s);
sb.ToString().CharAt(i);

但是第三个会操作 sb 内容的副本而不是实际内容吗?

but would the third operate on a copy of the contents of the sb rather than the actual contents?

是否有一种通用的方法可以将此功能添加到所有缺失的方法中?

Is there a common way of adding this functionality to all missing methods?

推荐答案

您可以将 Chars 成员集合用于 .charAt.同样,您可以使用 .Remove(i,1) 删除位置 i 处的单个字符.

You can use the Chars member collection for .charAt. Similarly, you can use .Remove(i,1) to remove a single char at position i.

这篇关于Java 和 C# 中 StringBuilder 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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