Use StringBuilder When Declaring A String?
Nov 20, 2009do you also have to use StringBuilder when declaring a String like this?:
View 11 Repliesdo you also have to use StringBuilder when declaring a String like this?:
View 11 RepliesWould the world of strings be better if stringbuilder had IndexOf?
View 2 RepliesI'm using VB's StringBuilder, and I was curious what is considered "best practice" for emptying the builder/setting it to a new string. Would it be something like this:[code]or is there a "Better" way?
View 2 RepliesHow can I check if a StringBuilder contains a certain character or string? There is no Contains method like the string class has.
View 8 RepliesHow do I refactor the method GetInvoiceNumbers to replace the SQL String concatenation with the StringBuilder class? Here is my code:
Private Function GetInvoiceNumbers() As System.Collections.Generic.List(Of Invoice) Implements InvoiceService.GetInvoiceNumbers
Dim invoiceList As New List(Of Invoice)
[Code].....
I am facing an amazing problem in my application. On my Developement server when I am running my application, then there is one function where I am trying to put whole stringbuilder contents in a string object. This Function is used for paging the reports.For that I am using a method of Stringbuilder.tostring() and when I chek the value of this statement (stringbuilder.tostring()) it shows no such interface is supported, which later on throws exception of system is out of memory. Here i am using .net 2.0 framework and sql server 2005 database.But when I run the application on stagging server then there is no such exception thrown.[code]
View 3 RepliesIn the middle of attaching a Google Custom Search Engine onto my page,I have a string which I would declare in C# as
String rxPattern = "<(?>"[^"]"|'[^']'|[^'">])*>";
How do I convert it to a string in VB?I mean store the same value into the string variable rxPattern using VB/VB.NET?
if this silly but I am trying to declare a string variable by the following line
[Code]...
I had a problem with CLR profiler. But it worked eventually and the results were outstanding. My app took 47 milliseconds to run before and after some adjustments CLR profiler runs in 6 miliseconds! This had to do with String values in a resource file which apparently takes a lot of time. So this got me thinking, isn't it more effective if you would declare 1 String at the top of your class and constantly change it throughout your code? Instead of creating a new String in a method when you need it.
Instead of using:
Dim text = "blalblalba"
You would do this everytime you needed a string:
text = "blalbla"
My question is... What exactly happens when you say text = ""? Does .net create a new String? It looks like you replace the text but what happens in the background? Would it be faster then declaring a new string?
I have a String variable in this page named "a".I wanted the scenario to be.When the page is started "a" will be null.But when the user selected an entry from the DetailView Control "a" will become "have".The following is my code. But i keep getting "a" = null even though i have selected an entry from the detailView control.[code]
View 2 RepliesI'm trying to return an array of strings from a function, and got surprised by an error.
I would have expected this to work, but it produces an error:
Public Function TestError() As String()
Return {"foo", "bar"}
End Function
[Code]....
I guess I'm unclear on the meaning of the {}'s - is there a way to implicitly return a string array without explicitly creating & initializing it?
I have a problem involving late binding, and I absolutely cannot for the life of me figure out how to fix it. I have spent hours researching the problem to no avail, so I am turning to stackoverflow as a last resort.The problem is pretty much this: I am creating a grocery list application. I have a class named Item which stores the name, price, quantity, and description of an item on the grocery list. I have a module named ListCollection which defines a Collection of Item objects. I have created an Edit form which will automatically display the currently selected ListCollection item properties, but whenever I attempt to fill the text boxes, it tells me that Option Strict disallows late binding. I COULD take the easy route and disable Option Strict, but I'd prefer to figure out what the problem is so I know for future reference.I shall paste pertinent code here. (Late binding error is in EditItem.vb)
[code]...
I have tried declaring a String variable and assigning the Item property to that, and I have also tried grabbing the value directly from the List item (not using the Get function), and neither of these made a difference.
How would I go about dynamically declaring a constant? (It's value is dynamic, not the variable name)
View 5 Repliesi'm using string builder for generating Passenger List in which i have used a tables i want to add dropdownlist into this Passenger . what i did is i have taken one main table --
strHTML1.Append("<table align=center cellpadding='0' cellspacing='0' width='100%'>");
strHTML1.Append("<tr>");
strHTML1.Append("<td>");
strHTML1.Append("Passenger");
[code]....
the prob is it is not show the dropdownlist when i run the project.
I'm trying to find out an easy way of bolding a string of my stringbuilder...if that is even possible.The stringbuilder eventually passes all the text to richtextbox..I'd like to bold this string
sb.AppendLine("--------------------------------")
and also
sb.AppendLine("Results for " & finalname)
[code].....
I am having the following string builder as msrtResult, which is quite long:
mstrResult.Append(rtbResult.Text).Append("})})" + Environment.NewLine)
How can I remove the last "," from mstrResult Now? (it is in the middle of that mstrResult and it is not the last character of the whole string since I am appending strings to it)I should do it before adding the newline.
I want to keep away from string object. I have a stringbuilder object, and I want to know if it contains 'Firefox'.
View 6 RepliesI have a sub that takes a string, replaces all characters that are not alphanumberic and or a "/" and replaces it with a space. Then it goes through and replaces all multiple spaces with a single space.
Right now I am using a string builder to do this. My problem is that this action must be done several hundred to thousand times depending on the filesize I am comparing it to (1 richtextbox line = 1 string)
I believe I should see a significant increase in performance if I can figure out how to do this using a single regex.replace function.How would I go about constructing a regex.replace function that would keep all alphanumberic characters and "/" and replace everything else with a single space?
[Code]...
I've got a stringbuilder variable, that I want to return the contents of, but if it's empty I want to return "|", so is it best to use stringbuilder.tostring in the compare statement e.g
If lReturnStringBuilder.ToString = String.Empty Then
lReturnStringBuilder.Append("|")
End If
[code].....
StringBuilder exists purely for the reason that strings in .NET are immutable, that is that traditional string concatenation can use lots of resources (due to lots of String objects being created).So, since an Int32 is also immutable why don't classes exist for multiple addition for example?
View 4 RepliesSuppose a stringbuilder is delimited by tab, I want to convert it to a matrix. How to do it?
View 3 RepliesI've found the following code in my boss's project:
Dim strBuilder As New System.Text.StringBuilder("", 1000000)
Before I call him out on it, I'd like to confirm whether this line actually sets a megabyte (or two megabytes in Unicode?) of memory aside for that one stringbuilder?
I have a textbox in which i have to write content inside stringbuilder.Following is my stringbuilder.
Dim strString As New StringBuilder()
strString.AppendLine("<table>")
strString.AppendLine("<tr><td>")
[code].....
vb.net
'strSearch = textBox.Text, columns 2 to 10 are the optional columns you want to search to. Function WhereQuery(ByVal strSearch As String, ByVal column1 As String, Optional ByVal column2 As String = "", Optional ByVal column3 As String = "", Optional ByVal column4 As String = "", Optional ByVal column5 As String = "", Optional ByVal column6 As String = "", Optional ByVal column7 As String = "",[code]..
sample output:
im also thinking on using stringbuilder to replace my strings.
In Visual Studio 2010 Ultimate, a VB.NET WinForms project, I am getting incorrect values for Environment.NewLine and StringBuilder.AppendLine; look at the result in a hex editor, they are resolving to two spaces.
View 6 RepliesI've created and populated a stringbuilder for a csv file. Normally I write it directly to the response object for the user to download through the browser.However, now I want to save it to a SQL DB image field. Is there a direct way to stream it in?
View 3 RepliesSo, 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 that has had calculations performed on it. Each line "corresponds" to a record from the database. A user will have to perform this file export usually on about 30-40 thousand records at a time. Now, even though I am using a StringBuilder, this still halts because of the pure mass amount of records.
What I do currently in the code is create one StringBuilder, append all the data (after calcs) to it, convert it to a String, add it to a List(Of String) to be returned from the Function, and then clear the StringBuilder, and do the same for the next row, and I do this until each row has been created and appended, converted, and then inserted into the List.
Then, another class receives this List(Of String) and takes each String and eventually appends it to a file.
Does anyone have an idea of how to improve this code and make it so it doesn't halt the server every time? The reason it wasn't found out until now is because when I tested it locally I was testing it on only 1-50 records at a time.
[Code]...
Is it from a sight of resources reasonable to use a StringBuilder already to concat two strings or is there a minimum concatenation operations that makes the StringBuilder efficient?
View 4 RepliesI would be grateful with some help with reading a text file into a Richtext box. The code I have at present appends the first line of text as I want it but the rest of the lines of text do not alter. I need a loop to read to the end of file and display in Richtext box. the code i have at present is this:-
[Code]...
I am using .net 2.0 and I am getting an exception of system is out of memory. My existing function takes datatable as input parameter which contains little bit large data (eg. more than 35000 rows) and in that function I am appending some xml node data and atlast I am returning the stringbuilder as a object.
[Code]...