stringbuilder

.net how to compare a stringbuilder to a string

∥☆過路亽.° 提交于 2019-12-12 04:37:06
问题 In vb.net (or C#) I can't figure out how to compare a stringbuilder to a string. I have searched quite a bit and can't find the answer. I had to write my own routine. Isn't there a better way? This doesn't work: Dim s As String = "abc" Dim sb As New StringBuilder("abc") If sb.Equals(s) Then Console.WriteLine(sb.ToString() + " DOES equal " + s) Else Console.WriteLine(sb.ToString() + " does NOT equal " + s) End If Results of that code is: abc does NOT equal abc Isn't there some way of comparing

System.ArgumentOutOfRangeException Parameter name: chunkLength at System.Text.StringBuilder.ToString()

帅比萌擦擦* 提交于 2019-12-12 03:23:15
问题 I have got below exception in a log file. System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: chunkLength at System.Text.StringBuilder.ToString() I believe this is because of string Builder which is not a thread safe. But I am stumbled on how to make my string builder to thread safe in below recursive function. public static class StringExtensions { /// <summary> /// The log key builder /// </summary>

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

不问归期 提交于 2019-12-12 02:38:52
问题 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. 回答1: Are you thinking of these backslashes here? If so, you are misreading the output: The backslashes are not actually in the string. They are only displayed here to make the representation valid according to C# syntax. If you were to output the string using Console.WriteLine , for example, it would not have

Can't do StringBuilder with Eclipse

心已入冬 提交于 2019-12-12 02:15:21
问题 Recently I started to learn Java. When I try to do the following code: public class Application { public static void main(String[] args) { StringBuilder sb = new StringBuilder(""); sb.append("a"); } } I get the following errors: The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files And Exception in thread "main" java.lang.Error: Unresolved compilation problem: The type java.lang.CharSequence cannot be resolved. It is indirectly referenced

Version of C# StringBuilder to allow for strings larger than 2 billion characters

孤人 提交于 2019-12-11 17:18:17
问题 In C#, 64bit Windows + .NET 4.5 (or later) + enabling gcAllowVeryLargeObjects in the App.config file allows for objects larger than two gigabyte. That's cool, but unfortunately, the maximum number of elements that C# allows in a character array is still limited to about 2^31 = 2.15 billion chars. Testing confirmed this. To overcome this, Microsoft recommends in Option B creating the arrays natively (their 'Option C' doesn't even compile). That suits me, as speed is also a concern. Is there

How to print the contents of stringbuilder in each line in a output text file in java

拜拜、爱过 提交于 2019-12-11 16:57:13
问题 I am working with an excel file which is a large one and i have to parse it using apache event library.So now i am somehow able to get the each cell value and contents of each cell and i am storing them in a Struingbuilder .So now my aim is to generate the text file in such a way so that each row and column will be look like the source excel file. I am giving the pic of the structure of the excel file. XXXXXX XXXXXXXXXXXX XXXXXXXX XXXXXXXXXXX XXXXXXXXX 1 DDD FFFFFF KKKK LLLL 2 KKK FFFFF KKK

StringBuilder and substring performance

与世无争的帅哥 提交于 2019-12-11 12:16:31
问题 About a performance issue related with String operation in Java : String s = ".........................,--content I wanted---,...."; Basically I will use for loop to iterate a long String and extract the contents between the , . Using substring is to record the begin index and end index during the iteration, and then do a s.subtring(begin,end) . Using StringBuilder , I will append every char between the comma during the iteration. Is there a performance issue about this? I mean which one will

Encrypting/Decrypting a string using a Affine cipher using the original 128 ASCII table

≯℡__Kan透↙ 提交于 2019-12-11 03:58:45
问题 So I am trying to encrypt a message using an affine cipher. I want to use all 128 ASCII characters to do it. I am getting an error when it comes to particular letters, Q, R, S, T, and U. They are not converting back correctly and displaying the incorrect decryption. Any ideas what is going on? Encrypted Message RUX[^adgjmpsvy| Decrypted Message ABCDEFGHIJKLMNOP/.-,+VWXYZ My code; public class EncryptionProject { public static void main(String[] args) { StringBuilder s = new StringBuilder(

StringBuilder namespace, c#, visual studio 2010

旧街凉风 提交于 2019-12-11 03:57:23
问题 What namespace does StringBuilder belong to? I typed: using System.Text.StringBuilder; But the intellisense, won't let me type StringBuilder . 回答1: Its very easy to determine in which namespace .NET class lives. you have two ways: Find interesting class in MSDN and in Inheritance Hierarchy section you can see FULL class name. Full class name means that before class name would be its namespace. For StringBuilder full class name would face as System.Text.StringBuilder . Just omit class name

What does ----s mean in the context of StringBuilder.ToString()?

给你一囗甜甜゛ 提交于 2019-12-11 03:46:15
问题 The Reference Source page for stringbuilder.cs has this comment in the ToString method: if (chunk.m_ChunkLength > 0) { // Copy these into local variables so that they // are stable even in the presence of ----s (hackers might do this) char[] sourceArray = chunk.m_ChunkChars; int chunkOffset = chunk.m_ChunkOffset; int chunkLength = chunk.m_ChunkLength; What does this mean? Is ----s something a malicious user might insert into a string to be formatted? 回答1: In the CoreCLR repository you have a