Environment.NewLine And StringBuilder.AppendLine Are Incorrect?
Aug 3, 2010
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.
I use Environment.NewLine, my colleagues use vbCrLf.When I'm doing a code review for them I want something that I can point to to say "use Environment.NewLine instead of vbCrLf"
Or, am I just peeing in the wind, and it doesn't really matter ?
Environnent.NewLine seems to be resolving to two spaces " " (as are vbCrLf and ControlChars.CrLF). Using StringBuilder, AppendLine is doing the same.I've been racking my brain and searching the Internet trying to figure out why this the way it is, but am coming up empty.
I am trying to generate .bat file based on user interface decisions. I need to have separation between lines. I'm trying:
Well I have been able to figure this out but what I want to do is make my string have a new line after 20 chars. I know how to find how many chars the string has but not how to insert environment.newline at 20 chars.I am using this to find the string length
If string.Length > 20 then 'Need to be able to insert environment.newline at 20 chars Else 'Normal string End If
To set the text of the excel cell to an multiline text i have used "sometext" & Environment.NewLine & "sometext".but it adds an space at the end of the first line
I'm not sure why the following code is not working as intended:
CODE:
Where litMessage is the name of the literal control and messageBody is the name of the string variable.
My intention is to output a string onto a web page and to replace the line breaks with a br tag so that it can be displayed on the page correctly. However, nothing is replaced. When viewing the page source, it looks like the line breaks still exist in the string. Similarly, when displaying the string via MsgBox, it displays normally as well. I have also tried wrapping the output with the pre tag and it displays the line breaks properly as well.
The string was originally entered by a user through the use of an asp:Textbox and saved into a MSSQL database. It's retrieved and displayed on another webpage using an asp:Literal control. The only thing that happens to the string before it is submitted is that it is trimmed (i.e. textbox.Text.Trim()).
Perhaps there is something I did not consider?
Edit #1: Due to time constraints, I've decided to just wrap the text with the pre tag. It's an acceptable work around as it preserves the line breaks. Unfortunately, it doesn't explain why the code didn't work in the first place. In the meantime, I'll just leave the question unanswered until I find a proper answer.
Edit #2: Solution found and answered below. UpdatePanel tag added to the question for future reference.
I have VB6 Dll which I am referencing in vb.net ,I am calling the following function in it. It working fine in developemnt environment but not in deployement environment.
Error Method not found: 'Boolean MyUtils._MyUtils.LoadMyObjectRecords(ADODB.Stream ByRef, System.Array ByRef)'.
i just want to make a program with first form to enter the serial if correct just continue to form2 if incorrect just a popup say like "Serial Incorrect" how i can make it ?
I'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?
i'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 --
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)
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 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?
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
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?
I'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?
'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.
I'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?
I'm using a richtextbox in vb.net. I need to maintain the text formatting while inserting a new entry.I have this issue solved although I am having difficulty with getting a new line between my new text and the prior existing text.Most solutions online presume you're working with rich textbox. text which accepts controlchars.lf, vbcrlf, and chr(10)... even chr(13) adds one single newline.How do i get the newline in rtf formatting?I prefer to have the new text entered at the top of the richtextbox as a user should see the latest update first.In addition, if this can be done more elegantly, I'm open for suggestions.Where you see controlchars.lf is where I want an rtf-based new line to show up. [code]
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 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.
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?
I 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:-