stringbuilder Questions

4

Solved

In many cases, we need to delete the last char of a StringBuilder/StringBuffer. For example, given a int[]{1,2,3}, to implement a String toString(int[] a) method, contacting each elements with a co...
Quadriplegic asked 8/2, 2014 at 11:41

9

Solved

I have a StringBuilder object that needs to be trimmed (i.e. all whitespace chars /u0020 and below removed from either end). I can't seem to find a method in string builder that would do this. He...
Backfield asked 6/3, 2011 at 19:47

12

Solved

I have a big CLOB (more than 32kB) that I want to read to a String, using StringBuilder. How do I do this in the most efficient way? I can not use the "int length" constructor for StringBuilder sin...
Nasturtium asked 30/1, 2010 at 22:36

4

Solved

Well I have two StringBuilder objects, I need to compare them in Java. One way I know I can do is sb1.toString().equals(sb2.toString()); but that means I am creating two String objects, is there...
Convulsive asked 13/6, 2012 at 2:16

4

Solved

I understand that I can call ToString().IndexOf(...), but I don't want to create an extra string. I understand that I can write a search routine manually. I just wonder why such a routine doesn't a...
Deviltry asked 31/8, 2009 at 23:55

4

Solved

How can I add a byte order mark to a StringBuilder? (I have to pass a string to another method which will save it as a file, but I can't modify that method). I tried this: var sb = new StringBuil...
Brakeman asked 10/3, 2014 at 17:7

6

Solved

What is the best method of writing a StringBuilder to a System.IO.Stream? I am currently doing: StringBuilder message = new StringBuilder("All your base"); message.Append(" are belong to us"); S...
Diurnal asked 10/2, 2010 at 11:34

2

String in Kotlin is immutable cannot work like ans[index] = value I wonder they are a simple way to make it work
Insurable asked 14/10, 2020 at 15:2

5

I'm a beginner to java and this is my first post on Stackoverflow. Although my initial code is similar to other posts here, my question relates to implementing StringBuilder and so the reason for t...
Sanguinaria asked 9/8, 2012 at 9:45

4

Solved

I've got a String array that I'm wanting to add to a string builder by way of LINQ. What I'm basically trying to say is "For each item in this array, append a line to this StringBuilder". I can d...
Condescendence asked 10/11, 2009 at 14:10

9

Solved

I could only do this with String, for example: String str = ""; for (int i = 0; i < 100; i++) { str = i + str; } Is there a way to achieve this with StringBuilder? Thanks.
Pastoralist asked 9/5, 2011 at 0:8

9

Solved

I'm trying to understand what the best practice is and why for concatenating string literals and variables for different cases. For instance, if I have code like this StringBuilder sb = new String...
Lophophore asked 9/4, 2012 at 19:51

11

Solved

How can I remove empty lines in a string in C#? I am generating some text files in C# (Windows Forms) and for some reason there are some empty lines. How can I remove them after the string is gener...
Learnt asked 4/10, 2011 at 12:14

3

Solved

// Reset resets the Builder to be empty. func (b *Builder) Reset() { b.addr = nil b.buf = nil } The code snippet is from the source code in go strings.Builder. The buffer is set to nil instead ...
Methodius asked 30/4, 2020 at 2:48

3

Solved

I had a look at string escape into XML and found it very useful. I would like to do a similar thing: Escape a string to be used in an XML-Attribute. The string may contain \r\n. The XmlWriter cla...
Obstruent asked 16/12, 2010 at 18:29

7

Solved

I have a StringBuilder object, StringBuilder result = new StringBuilder(); result.append(someChar); Now I want to append a newline character to the StringBuilder. How can I do it? result.append...
Helsinki asked 26/1, 2013 at 7:13

5

Solved

I am trying to save a file using DialogResult and StringBuilder. After making the text, I am calling the following code to save the file: if (dr == DialogResult.OK) { StreamWriter sw = new Str...
Firedog asked 16/11, 2011 at 12:5

3

Solved

I tried to append the items in a List<string> to a StringBuilder with LINQ: items.Select(i => sb.Append(i + ",")); I found a similar question here which explains why the above doesn't w...
Indopacific asked 24/11, 2010 at 12:32

3

Solved

Does StringBuilder have a limit of characters for maximum capacity in JAVA. StringBuilder url=new StringBuilder(); stmt = connnection.createStatement(); String sql="SOME QUERY"; rs = stmt.execute...
Figueroa asked 28/6, 2016 at 5:28

8

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...
Presumable asked 6/7, 2010 at 7:17

5

Solved

I have read some articles about the pros and cons of String and StringBuilder in the Java Programming language. In one of the articles, the author mentioned that: StringBuilder is not Thread-saf...
Legato asked 11/11, 2014 at 7:59

12

Solved

I understand the benefits of StringBuilder. But if I want to concatenate 2 strings, then I assume that it is better (faster) to do it without StringBuilder. Is this correct? At what point (number...
Weinshienk asked 1/12, 2009 at 12:8

5

Solved

What is the best (shortest and fastest) way to check if StringBuilder ends with specific string? If I want to check just one char, that's not a problem sb[sb.Length-1] == 'c', but how to check if ...
Audiophile asked 10/7, 2013 at 20:19

3

Solved

I was trying to check that a String is a palindrome using StringBuilder and reverse(). For a word with no symmetry like "chan" it correctly returns false, but it also returns false for genuine pali...
Whitehurst asked 1/9, 2019 at 11:11

1

Solved

In Java, Following code is one way to achieve. StringBuilder result = new StringBuilder(); result.append(someChar); result.append("\n"); Idiomatic way of doing it in kotlin?
Stopwatch asked 29/8, 2019 at 7:27

© 2022 - 2024 — McMap. All rights reserved.