stringbuilder

Why doesn't StringBuilder have IndexOf method?

I understand that I can call ToString().IndexOf(...), but I don't want to create an extra string. I understand that I can write search routine manually. I just want to know, why does not such routine already exist in the framework. ...

StringBuilder vs String concatenation in toString() in Java

Given the 2 toString() implementations below, which is prefered public String toString(){ return "{a:"+ a + ", b:" + b + ", c: " + c +"}"; } or public String toString(){ StringBuilder sb = new StringBuilder(100); return sb.append("{a:").append(a) .append(", b:").append(b) .append(", c:").append(c) ...

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().CharA...

When and Why Should I Use TStringBuilder?

I converted my program from Delphi 4 to Delphi 2009 a year ago, mainly to make the jump to Unicode, but also to gain the benefits of all those years of Delphi improvements. My code, of course, is therefore all legacy code. It uses short strings that have now conveniently all become long Unicode strings, and I've changed all the old ANSI...

Strings are immutable - that means I should never use += and only StringBuffer?

Strings are immutable, meaning, once they have been created they cannot be changed. So, does this mean that it would take more memory if you append things with += than if you created a StringBuffer and appended text to that? If you use +=, you would create a new 'object' each time that has to be saved in the memory, wouldn't you? ...

String / StringBuilder what volume do you use one over the other

It's Friday refactor time!!! I have an object that I use to generate SQL statements. oDb.From is set once. Then meta data may add join(s) over time till we combine it all and pass it back. So the Q is, What # of times do I keep syntax oDb.From += before I replace it with sbFrom.Append() Is that # 3, 4, or 15 times? Or is it rea...

Dumping a Java StringBuilder to File

What is the most effecient/elegant way of dumping a StringBuilder to a text file? you can go: outputStream.write(stringBuilder.toString().getBytes()); But is this efficient for a very long file? Is there a better way? ...

LINQ to append to a StringBuilder from a String[]

I've got a String array that I'm wanting to add to a string builder by way of LINQ. What I'm basically trying to say is "For each item in this array, append a line to this StringBuilder". I can do this quite easily using a foreach loop however the following code doesn't seem to do anything. What am I missing? stringArray.Select(x => s...

Hibernate: OutOfMemoryError persisting Blob when printing log message

I have a Hibernate Entity: @Entity class Foo { //... @Lob public byte[] getBytes() { return bytes; } //.... } My VM is configured with a maximum heap size of 512 MB. When I try to persist an object which has a 75 MB large object, I get an OutOfMemoryError. The names of the methods in the stack trace (StringBuilder,...

getting better performance appending strings than going through standard Java stringbuilder.append

Hi, as part of the process of populating a search engine, I populate a Berekely-DB value-store as well. This process is repeated each night and at the moment +/- 60% of the total running time each night is caused by creating the values to be inserted into the value-store ( so excluding the actual insertion into Berekely-DB and the time...

interesting OutOfMemoryException with StringBuilder

I have the need to continuously build large strings in a loop and save them to database wich currently occasioanlly yields an OutOfMemoryException. What is basically going on here is I create a string using XmlWriter with StringBuilder based on some data. Then I call a method from an external library that converts this xml string to so...

.NET strings and reference type parameters

I was wondering if any one could explain this code to me... public void SomeMethod() { StringBuilder sb = new StringBuilder(); AppendFoo(sb); String foo = sb.ToString(); // foo is "foo" String s = String.Empty; AppendBar(s); String bar = s; // bar is empty } public void AppendFoo(StringBuilder x) { x.Appen...

Groovy literal StringBuilder/StringBuffer

Hi, Groovy supports a literal syntax for creating a StringBuilder/StringBuffer instead of the usual def sb = new StringBuilder() However, I can't seem to remember (or find on Google) the correct syntax. Thanks, Don ...

When to use StringBuilder?

I understand the benefits of StringBuilder. But if I want to concatenate 2 strings, then I assume that it is better (faster) to do it without StringBuilder. Is this correct? At what point (number of strings) does it become better to use StringBuilder? ...

Unsafe code and fixed statements with StringBuilder

I was wondering about how passing a String or a StringBuilder to a C function which output a string by parameter. I've found a great answer in http://stackoverflow.com/questions/1687558/calling-unmanaged-function-from-c-should-i-pass-stringbuilder-or-use-unsafe-cod But I have a doubt. Anyone can explain to me why the garbage collector ...

Is there any scenario where the Rope data structure is more efficient than a string builder

Related to this question, based on a comment of user Eric Lippert. Is there any scenario where the Rope data structure is more efficient than a string builder? It is some people's opinion that rope data structures are almost never better in terms of speed than the native string or string builder operations in typical cases, so I...

.NET Refactoring Tools - String to StringBuilder

Is Refactor Pro the only .NET Refactoring tool that supports the String to StringBuilder refactor? I'm looking for one that has a trial version of this feature to see if I like it enough to purchase. The overall goal is to tidy up another developer's VB.NET code. ...

[C#] Clearing a StringBuilder Object's Current String

Possible Duplicate: best way to clear contents of .NETs StringBuilder Is there a quick and easy way to get rid of what a StringBuilder currently holds? I was looking for a Clear() method but I can't find it. ;) I would to do stringBuilderObject = "" or something along those lines. ...

Is there a quicker way to process a sequence of element than using a loop?

Here I am storing the elements of a datagrid in a string builder using a for loop, but it takes too much time when there is a large number of rows. Is there another way to copy the data in to a string builder in less time? for (int a = 0; a < grdMass.RowCount; a++) { if (a == 0) { _MSISDN.Appe...

StringBuilder.Append Question

I would like to know the difference (if there is any) between : StringBuilder sb = new StringBuilder(); sb.Append("xxx"); sb.Append("yyy"); sb.Append("zzz"); And : StringBuilder sb = new StringBuilder(); sb.Append("xxx") .Append("yyy") .Append("zzz"); ...