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.
...
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)
...
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...
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, 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?
...
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...
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?
...
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...
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,...
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...
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...
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...
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
...
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?
...
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 ...
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...
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.
...
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.
...
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...
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");
...