FAQ Database Discussion Community


creating multiple stringbuilders WTR to count

c#,stringbuilder
If i have a count say item =5. I want to generate 5 string builder objs. How can this be done? string[] features = UserBL.GetFeaturesByRole(Session["Role"].ToString().Trim()).TrimEnd(',').Split(','); in features i will have features. So according to the count i need to generate stringbuilder objs....

What is the point of creating both AbstractStringBuilder and StringBuilder?

java,stringbuilder
Why did Java developers didn't create one class, AbstractStringBuilder and rename it to StringBuilder? e.g., the method in AbstractStringBuilder: public AbstractStringBuilder append(double d) { FloatingDecimal.appendTo(d,this); return this; } and the method in StringBuilder: @Override public StringBuilder append(double d) { super.append(d); return this; } I suppose we can keep only one...

String Builder and string size

c#,string,memory,stringbuilder
Why StringBuilder Size is greater than string(~250MB). Please read the question. I want to know the reason of size constraint in the string, but not in stringbuilder. I have fixed the problem of reading file. Yes, I know there are operation, we can perform on string builder like append, replace,...

StringBuilder setLength() [duplicate]

java,stringbuilder
This question already has an answer here: Why stringbuilder stops adding elements after using the null character? 3 answers class Test { public static void main(String args[]) { StringBuilder sb = new StringBuilder("123"); System.out.println(sb + "_"); //123_ // expected ouput sb.setLength(2); System.out.println(sb + "_"); //12_ // expected output sb.setLength(3);...

Nice looking table with StringBuilder

java,stringbuilder
I know that "printf" method can use string formatting. My question is : Is there a way to create a nice looking table with StringBuilder class? For example: |Id|Category|Level|Space|Type|Adress|Dimension|Limits| And under that row, i must add the values of each columns! Doing something like that : example but with StringBuilder...

The string is getting the wrong value

java,string,stringbuilder
I am trying to build a string like 11 11 but I am facing problem I am getting for start the following string 98 11 and not 11 11. How can I fix that? I appreciate any help. Character number = newName.charAt(2); //here number is 1 Character numberBefore = newName.charAt(1);...

Java new String and new StringBuilder in heap behavior

java,string,garbage-collection,stringbuilder
Does the String pool reside on the heap? If yes, are String literals eligible for garbage collection? When using new String("abc"), we know that it creates an object on the heap and places the String literal in the String pool. So my 2nd question is: Does new StringBuilder("abc") behave...

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

c#,.net,clr,stringbuilder,reference-source
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...

Is StringBuilder threadsafe (using it with parallelStream)?

java,multithreading,thread-safety,java-8,stringbuilder
My code: StringBuilder sb; sb = new StringBuilder(); events.parallelStream().forEach((event) -> { sb.append(event.toString()); sb.append("\n"); }); I don't care about the order of the events.toString() in the final result. But I care that the events.toString() will correctly appear one line after another, without mixing / messing up of course. Is parallelStream (instead...

The Result is not coming in correct format in Java code

java,string,algorithm,stringbuilder,system.out
Here in I want the Stringbuilder to append the result of each calculation. But its not coming in the correct format. In the code I am trying to find all the comman factors of two numbers and getting the kth value. But my result is not coming in the expected...

Mutability of string when string doesn't change in C#?

c#,string,immutability,stringbuilder,mutable
If the string operation doesn't change the value of string, Will that end up in creation of new instance?Eg; string str="foo"; str+=""; i know the difference between string and stringbuilder in C#....

How can I replace script content of html in a StringBuilder

c#,.net,stringbuilder
I have a HTML page in my .Net project in that I have one script section <script language="javascript" type="text/javascript"> s.property1="|*|property1|*|" s.property2="|*|property2|*|" <script> In the c# code I'm reading the html file and replacing the "| * |property1| *|" values like below StringBuilder siteCode = new StringBuilder(); //code to append html...

When calling append on stringbuilder, are we adding strings to the heap?

c#,.net,memory-management,stringbuilder
I am wondering about the benefits of using stringbuilder when it comes to memory usage in C#. If you have the following scenario: var strBuilder = new StringBuilder(); for(int i=0;i<1000;i++) { strBuilder.Append(i); /// is this not calling i.ToString(); ??? strBuilder.Append(','); /// this i character comma strBuilder.Append(" and "); /// this...

Append Strings - Performance issue - Java 6

java,string,performance,append,stringbuilder
I need to repeatedly append strings (for about 50 times), which is a substring of another StringBuilder. I need to do this for around 30k inputs. It takes me a time of around 6 minutes. StringBuilder input = new StringBuilder(10000); StringBuilder output = new StringBuilder(10000); //for loop till end of...

LibGDX Android Stringbuilder most efficient Way?

java,android,libgdx,stringbuilder
Good Day to you all, i have a little Question, what would be the best way to often add a lot of different Strings to an other String especially in LibGDX? blockString=new StringBuilder(blockString).append(String.valueOf(blockCount.length/2+i)).append("][").append(String.valueOf(f)).append("]").append(String.valueOf(t)).toString(); I have to do this method several hundred Times in as little Time as possible. Does anyone...

RTFLib turns { and } into / [closed]

c#,richtextbox,stringbuilder,brackets,rtflib
I'm not sure if this is widely used as I cannot find much about it online. It's a library that constructs formatted text for a RichTextBox. I've boiled the issue down to StringBuilder though. The RTFLib will find { and } and turn it into //{ and //} to try...

Check if each letter in ArrayList is a certain character?

java,for-loop,arraylist,character,stringbuilder
Firstly, I'm SUPER new to stackoverflow (so excuse my ugly formatting), and have only a few years of programming experience (about 6 programming classes total) I'm working on a hangman project. I've elected to use a StringBuilder for some of it. For example, I want to check what index or...

How do I use StringBuilder in Java [closed]

java,arrays,data,printing,stringbuilder
I'm using stringbuilder in a method to print out a representation of the data that I stored in an array. So the code looks like this: public String toString(){ StringBuilder S = new StringBuilder(numRows * (num(ols + 1))); for(int i = 0; i < numRows; i++){ for(int j = 0;...

Alternative to switch — replacing characters

java,switch-statement,stringbuilder
I was required to write a program for class which: Accepted a .txt file Convert numbers 0-9 in the file to their text equivalent (if the number is at beginning of sentence, use uppercase) Print the finished sentences to a new file Example: The 8 eggs were separated into 3...

splitting a StringBuilder value without String.split()

java,regex,string,split,stringbuilder
I'll be processing texts and will split along the way for one, its substrings on regular expressions like String.split() does. i'm looking to do these on StringBuilder for speed concerns. From what i know, StringBuilder has no such method. all i can do is to invoke String.split() and turn the...

Pass Stringbuilder message from Json [MVC-Controller]and render it in view

jquery,ajax,json,asp.net-mvc,stringbuilder
I am trying to pass a StringBuilder message as an extra data back to ajax call but I am failing to manipulate it in client side. Below is the way I append message to StringBuilder and pass it back. StringBuilder retMessage=new StringBuilder(); retMessage.Clear().AppendLine("Successfully added the user!"); //Clear will done only...

How to append single quotes into both side of stringBuilder object in java

java,string,append,stringbuilder
I would like to add single quotes into an array of string. If I has 5 values.(1,2,3,4,5). I need like this '1','2','3','4','5' I have tried some like below but I am getting error public class Main() { StringBuilder values=new StringBuilder(); values=getValues(1); System.out.println(values.toString()); public StringBuilder getValues(int productid){ StringBuilder Variable_1=new StringBuilder(); Variable_1=get(productid);...

Splitting a text file into multiple files by specific character sequence

java,text,split,bufferedreader,stringbuilder
I have a file with the following format. .I 1 .T experimental investigation of the aerodynamics of a wing in a slipstream . 1989 .A brenckman,m. .B experimental investigation of the aerodynamics of a wing in a slipstream . .I 2 .T simple shear flow past a flat plate in...

Binary to Ascii trouble with string builder (JAVA)

java,binary,ascii,stringbuilder
I have a string and I want to change it to binary but then later in the code I wish to change it back into ascci. How would I do that? Here is my code so far: String word = JOptionPane.showInputDialog("Insert word"); String s = word; byte[] bytes = s.getBytes();...

Using StringComparer with StringBuilder to search for a string

c#,string,search,stringbuilder,culture
I need to use globalization rules to search for all occurrences of a string within a document. The pseudocode is: var searchText = "Hello, World"; var compareInfo = new CultureInfo("en-US").CompareInfo; DocumentIterator start = null; // the start position if a match occurs var sb = new StringBuilder(); // the document...

Why does java have StringBuilder or StringBuffer? [duplicate]

java,string,stringbuilder,stringbuffer
This question already has an answer here: Why do we have String class, if StringBuilder or StringBuffer can do what a String does? [duplicate] 7 answers There are many differences between String and (StringBuilder or StringBuffer) like mutability and many string operations May be this question seems a bit...

How search a datum in ArrayList with indexOf [closed]

java,search,arraylist,stringbuilder,indexof
How search a datum in ArrayList with indexOf ArrayList<StringBuilder> state = new ArrayList<StringBuilder>(); state.add(new StringBuilder("A")); state.add(new StringBuilder("B")); state.add(new StringBuilder("C")); state.add(new StringBuilder("D")); System.out.println(state.indexOf(new StringBuilder("B"))); //Out: -1 ...

Delete unwanted chars in a String Java

java,regex,string,stringbuilder
I'm trying to write a simple program that takes in a String as input. If the String matches a regex expression then it is returned. If not, I need to go through it, find each char that is causing the problem and remove it. The problem I'm running into is...

Overloaded method call has alternatives: String.format

string,scala,unicode,stringbuilder
I wrote the following Scala code below to handle a String that I pass in, format the String, append it to a StringBuilder and return the formatted String with escaped unicode back to my caller for other processing. The Scala compiler complains of the following on the lines where there...

Disadvantages of using/creating String objects in a loop

java,stringbuilder
What is the disadvantage of: for(int i=0;i<10;i++) { String str = ""+i; System.out.println(str); } over: String str; for(int i=0;i<10;i++) { str = ""+i; System.out.println(str); } and: for(int i=0;i<10;i++) { StringBuilder strBld = new StringBuilder("Hello"+i); System.out.println(strBld.toString()); } With respect to total number of object created in memory?...

Spaces between elements in RPN expression java

java,stringbuilder,rpn
I have a method getRPNString(), which returns Reverse Polish Notation string. I want to split this string by spacebars to calculate it. Now I can't understand how to add spacebars in my RNP string right, because it's not working with two digits numbers. public class Calc1 { public static void...