Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

differences between StringBuilder in Java and C#

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);

which seems to be missing in C#.

I suppose the first two could be modelled by

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

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?

like image 710
peter.murray.rust Avatar asked Jan 24 '23 03:01

peter.murray.rust


1 Answers

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

like image 75
Joe Avatar answered Jan 25 '23 16:01

Joe