stringbuilder

Where are strings more useful than a StringBuilder?

Lot of questions has been already asked about the differences between string and string builder and most of the people suggest that string builder is faster than string. I am curious to know if string builder is too good so why string is there? Moreover, can some body give me an example where string will be more usefull than string build...

Java.lang.NoClassDefFoundError java.lang.StringBuilder from code using java.lang.StringBuffer

Hi, I know there are plenty of questions regarding this error, but I haven't found it easy to find one exactly like mine. Here goes. I have a pretty small application that writes DB data to a csv file and then uploads it to a server. I have it running on my local box out of eclipse which is great, but the final version needs to be run...

NewLine Characters not working when formatting email with StringBuilder

I am doing simple formatting for an email with StringBuilder and have code that looks like the following. StringBuilder message = new StringBuilder(); message.append("Name: " + model.getName() + "\r\n"); message.append("Organization: " + model.getOrganization() +"\r\n"); message.append("Comment: " + ...

How would you refactor this Asp.net MVC 2 Html Helper?

Hi All, Quick question. How would you refactor this Asp.net MVC 2 HtmlHelper? Specifically would it make sense to use the TagBuilder class in this scenario? public static MvcHtmlString BusinessDisplayContacts(this HtmlHelper helper, string phone, string cellPhone, string fax, string website, string email, bool hide...

StringBuilder capacity()

I noticed that the capacity method returns StringBuilder capacity without a logic way ... sometime its value is equals to the string length other time it's greater... is there an equation for know which is its logic? ...

Is it better practice to use a few tag builders or a StringBuilder to generate an Object tag? ASP.NET MVC

Hello SO: I wrote an HTML helper to generate a YouTube embed link. It has 3 parameters, YouTubeID, Width, and Height. I originally wrote it with a StringBuilder, but then I decided to try to use the TagBuilder (well, a few of them). Here are the two different returns: //Tag Builder public static string YouTube(this HtmlHelper helper, ...

[VB.Net] How do I dispose a TextBuilder ?

Hello there! Out of pure curiosity, is there a way to free the memory used by a StringBuilder, other than the obvious MyBuilder = New StringBuilder and MyBuilder.Remove(0, Length) (although I guess the later wouldn't free anything, would it?) Thanks! CFP. ...

The correct way to retreive data from a HttpWebRespose Stream then add text.

I am trying to retrieve a web page, add some text at the top of the page then I will be sending off the string. Here is a example framework of what I am trying to do. Is this the correct method or am I doing a big no-no somewhere? HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.example.com"); var responce = (HttpW...

StringBuilder or +=

Hello, I receive around 5 messages per second. Each of them has a string, which I concatenate to a master string that contains all the received messages string _masterText = ""; public void AddNewMessage(string text) // this is going to be call at least 5 times/second { _masterText += text; } Is this the ...

Server halts due to large StringBuilder instance in memory

So, I have this code that grabs a bunch of data from the database, and performs a bunch of calculations on that data. However, this is not what is causing the halt. The halt is coming in when I take all that "final" data that has been prepared, and go to write that into a text file. Each line in the text file is being created from data ...

(java) Remove last character of a StringBuilder ?

When you have to loop through a collection and make a string of each data separated by a delimiter, you always end up with an extra delimiter at the end, e.g. for(String serverId : serverIds) { sb.append(serverId); sb.append(","); } Gives something like : serverId_1, serverId_2, serverId_3, I would like to delete the last character...

ASP.NET MVC FileContentResult SLOW

We are using it to return a file for an export. When we run this export on a lot of records, it takes close to 10 minutes to run. Here is a code snippet of the code that actually calls the File() method and returns the result. Public Function Export(ByVal ID As Integer) As FileContentResult Dim str As String = String.Empty Dim data(...

Loop takes forever with large count

This loop takes forever to run as the amount of items in the loop approach anything close to and over 1,000, close to like 10 minutes. This needs to run fast for amounts all the way up to like 30-40 thousand. 'Add all Loan Record Lines Dim loans As List(Of String) = lar.CreateLoanLines() Dim last As Integer = loans.Count - 1 For i = 0 T...

Java CLI Application performance with StringBuilder

General: I am writing a socket client that receives "Market" data/quotes all the time (never ending loop) from some server side (distant one). i am dividing the data in to chunks so i can use it. each chunk contains about 200 characters and needs to be converted in to an array. After a chunk was divided it is been parsed in to a List (No...

how to get a String with String.Format to execute?

I have a little chunk of code (see below) that is returning the string: string.Format("{0}----{1}",3,"test 2"); so how do I get this to actually "Execute"? To run and do the format/replacement of {0} and {1}? My Code snippet: StringBuilder sb = new StringBuilder(); sb.Append("{0}----{1}\","); sb.AppendFormat(ReturnParamValue(siDTO, ...

How to efficiently overwrite parts of a string by index in .NET ?

Hi, In my .NET program I allow a user to define "fields" which are values calculated by the business logic. These fields have a position and length, so that they can all be inserted into a single output string at a given index. I also allow a user to specify default content of this output string. If no field is defined to replace a give...

How can a StringBuilder best be converted to a String[]?

The following code sort of works, but fixes the number of elements in String[]. Is there a way to make a String[] add the number of elements needed dynamically? private static StringBuilder names = new StringBuilder(); ... public String[] getNames() { int start = 0; int end = 0; int i = 0; String[] nameArray = {"","","",...

Am I undermining the efficiency of StringBuilder?

I've started using StringBuilder in preference to straight concatenation, but it seems like it's missing a crucial method. So, I implemented it myself, as an extension: public void Append(this StringBuilder stringBuilder, params string[] args) { foreach (string arg in args) stringBuilder.Append(arg); } This turns the follo...

Regex replacements inside a StringBuilder

I'm writing the contents of a text file to a StringBuilder and I then want to perform a number of find/replace actions on the text contained in the StringBuilder using regular expressions. I've run into a problem as the StringBuilder replace function is not capable of accepting regular expression arguments. I could use Regex.Replace o...

StringBuilder.ToString() is adding '\' characters in the beginning and ending of the string

StringBuilder.ToString() is adding '\' characters in the beginning and ending of the string. Why is this? Before calling .ToString() the string doesn't have the '\' character. ...