Questions tagged [stringbuilder]
Stringbuilder is a class that provides a convenient and efficient way of working with text data in Java and .NET framework.
2,126
questions
1
vote
2
answers
44
views
Issue converting stringBuilder + forloop to stream + map
What I am trying to achieve:
I would like to convert a StringBuilder + forloop, like this:
public String question(List<MyPojo> myPojos) {
final StringBuilder stringBuilder = new ...
1
vote
1
answer
55
views
Is using StringBuilder in place of String within function parameters a good idea? [closed]
I need some suggestion on using StringBuilder as against String inside function parameters. The basic structure of my program is as below :
There are several functions running sequentially .
Based on ...
0
votes
1
answer
26
views
Attaching a attachment to a calendar event using powershell
I am creating a calendar event using powershell. Ideally, I'd like to avoid using modules if possible because I feel like what I'm trying to do is very possible with what I have, but if a module is my ...
1
vote
2
answers
107
views
how to reuse StringBuilder in a loop?
What am trying to do here is to improve speed performance by using StringBuilder outside the loop and clear StringBuilder in each cycle for reuse , but seems like this approach doesn't always work , ...
0
votes
3
answers
51
views
How to add All the elements of an integer array in a StringBuilder using stream adding extra space to each of the element
I am trying to add all the elements of an int array brr into a StringBuilder res using the following code.
I tried the following way
StringBuilder res = new StringBuilder();
Arrays.stream(brr)....
0
votes
4
answers
78
views
StringBuilder equals() method is not working as expected
I am solving the 125. Valid Palindrome problem in leetcode. For testcase
A man, a plan, a canal: Panama
with below code, it is returning false:
class Solution {
public boolean isPalindrome(...
-1
votes
1
answer
85
views
Is it worth the effort to empty a long string?
I used a StringBuilder to write an SQL query in .NET.
After I perform the query, is there a point in manually setting the contents of the string to ""?
I'm guessing this is already being ...
0
votes
0
answers
39
views
Replacing redundant HTML string using Jsoup, Pattern class and StringBuilder
I have a big html string in form of byte[] which size is about 59kb and I need to decrease it as much as I can. I manage to remove some redundant string and hit size of 36kb after parsing. However, I ...
1
vote
0
answers
42
views
Why is my searching algorithm in Java not working? [duplicate]
We just started Java at school and I was wondering why this search algorithm isn't working:
the purpose of the entire code is to store N wine bottles (object) in a cellar (array) and to search for the ...
0
votes
2
answers
114
views
Why my StringBuilder.AppendLine method won't save non-english letters in C# .NET?
I am working on a school project and the task was to create an application, which one of the features is to save multi-lined text (user input) into a string. I know some parts of the code might be ...
0
votes
1
answer
88
views
How to create an XML file with several roots from a StringBuilder C#
I'm a mechanician who has to develop tools yo manage xml files.
I have an issue and I need your help.
One of my xml file that I have to manage has several roots. Don't ask why, my provider will not ...
0
votes
0
answers
45
views
Java Heap Error for StringBuilder while reading zips
I have a scenario to read zip files from a server URL. But I get a Java heap error when i append the string in the stringbuilder
public static void main(String args[]) {
String url = &...
-2
votes
1
answer
56
views
Empty line at the end of code needs removing [closed]
I have this method that returns a string where a triangle appears on the left size of the diagram, followed by horizontal lines. I used a stringBuilder for this method. The problem is that there is an ...
0
votes
0
answers
44
views
im trying to send an email using an html file for structure. but its returning me the plain text
so im very new to programing and was tasked to send an email. the email gets sent. but it seems im either not using the html. or im rewriting or deleting it somehow. can someone give me a hand to ...
0
votes
0
answers
21
views
How To Open An Existing File in a New Window Tab? [duplicate]
I'm currently trying to implement an icon that displays a csv file's content in a new tab. Right now, it's only redownloading the file when I click on it.
Here's the code snippet:
string ...
0
votes
2
answers
43
views
How to remove a letter from the terminal and replace it with a new one in java?
So I am trying to make a Simon Says game where the user would have to repeat what the console has shown back to it. So for me so far I have made it work so that the characters have been showcased to ...
-2
votes
3
answers
130
views
How to format string in Java when the value goes from parameters? [duplicate]
I have a problem: I need to get a phone number as a string "79991111111" and convert it to this type of string "+7 (999) 111-11-11".
As i got it i'm able to do it by using a String....
0
votes
1
answer
31
views
I'm having trouble implementing the download tag in my <a> for the download of my file
I have this program that has a C# controller that uses StringBuilder to write to a CSV file which would be downloaded when clicked.
Here's my C# function:
public ActionResult GenerateCSV()
{
...
0
votes
1
answer
89
views
what is the most efficient way to clear an atomic reference to stringbuilder
If i have an AtomicReference to a StringBuilder defined as so:
private AtomicReference<StringBuilder> stringBuffer = new AtomicReference<>(new StringBuilder());
which method is best for ...
-2
votes
2
answers
67
views
Questions about StringBuilder Array
I'm trying to initialize a StringBuilder with "". These are 2 samples, the first one doesn't work while the second one works. Can anyone explain a bit more? Is this because StingBuilder is ...
0
votes
2
answers
51
views
Trouble with String Builder: Filtering Characters in Java Swing JTextField
I'm fairly new to Java and stackoverflow.
Please alert me if I make a mistake or if I provide insufficient information.
I'm working on a Java Swing project and trying to use a custom DocumentFilter ...
0
votes
3
answers
89
views
How do I compare a rotating StringBuilder with a normal String in Java
Here is the question: Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.
A shift on s consists of moving the leftmost character of s to the ...
0
votes
0
answers
59
views
why is this StringBuilder code not giving the desired output
I want to compress the string using StringBuilder but the code is not working as expected. It is simply returning the print statement.
import java.util.*;
public class string_compression {
public ...
2
votes
2
answers
88
views
js function as string inside StringBuilder C#
I'm new in .net platform and I'm curious about how can I pass js function with curly brackets as string inside StringBuilder.AppendFormat() c#.here is what I'm willing to do
StringBuilder sb = new ...
0
votes
2
answers
109
views
Why does Java StringBuilder use 2147483639 as safe bound?
Java version: openjdk 11.0.19
When I was looking at the source code of StringBuilder, I noticed that it checks if the capacity exceeds 2147483639 when you use the append method.
I'm curious why this ...
2
votes
3
answers
89
views
Does Java Set<String> contains() check for existence of StringBuilder?
Does Java Set contains() know how to check for the existence of StringBuilder?
I am running this problem in Leetcode. "Find Unique Binary String". Note this Question is not about Solving the ...
-1
votes
1
answer
87
views
Using String.Join in String Builder C#
I am trying to create a csv string from a list of GUIDs (around 10000) of them. My snippet is below.
private string GetAppInformationForCache()
{
StringBuilder appInfo = new ();
var ...
-1
votes
1
answer
33
views
ensure removal of password at end of string using StringBuilder with java
I need to ensure that always at the end of this string when there is a password, from there it leaves the password masked and does not display.
Remembering that in the end, the value cannot always be ...
0
votes
1
answer
55
views
Why is there a difference in memory address when using String Builder keyword in C#?
according to the theory after manupaliting string using String Builder keyword both memory address must be same, but i get wrong answer. could anyone please explain this.
class Program
{ ...
0
votes
2
answers
139
views
StringBuilder AppendFormat with dynamically params array
I am dynamically building a SQL statement using StringBuilder. The criteria are defined by the user and there is no limit.
There is no problem with the string format, it is generated fine.
Let's say ...
-2
votes
1
answer
190
views
What's the wrong with StringBuilder in code
class Solution {
public String mergeAlternately(String word1, String word2) {
int length = word1.length() + word2.length();
StringBuilder ans = new StringBuilder(length);
...
0
votes
0
answers
32
views
Is there any way to return comma separated string containing the values of the properties of a C# object.? [duplicate]
Looking for Solution to return property names on header and then values
public override string ToString()
{
StringBuilder builder = new StringBuilder();
var props = this.GetType()....
-3
votes
3
answers
222
views
How to replace entire StringBuilder value?
I need to assign a new string value to completely replace the existing string value in a StringBuilder object.
But,
sb.Append() will only add to the end of a string, and sb.Insert(0,stringVal) will ...
0
votes
4
answers
104
views
How can I do this but using StringBulider
I am trying to replicate this code using StringBuilder but can't figure out how.
What this does is check a given string (tweetText) with an array of Strings (usernames) and if is a match replaces the ...
-3
votes
1
answer
66
views
problem while comparing char with relational operators
import java.util.Scanner;
public class ValidString {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the String: &...
-4
votes
2
answers
184
views
String append in java
I am constructing single string value based on some other string details, which is as below.
But don't wants to add if any of DTO value is null or empty. How can I add it in java.
String dummyVal = ...
2
votes
1
answer
59
views
Azure Function StringBuilder object persists across multiple runs and appends to itself when writing new text files
So I have created my first Azure Function (4.0) (.NET 7.0) that takes an input text file from an Azure Storage Blob Container, does some processing on it, then generates additional text files based on ...
0
votes
1
answer
87
views
Stringbuilder does not create new instance if the initial capacity set too small but a book says otherwise
StringBuilder sb = new StringBuilder("test", 4);
sb.Append('\n');
sb.AppendLine("test1");
sb.AppendLine("test2");
sb.AppendLine("test3");
sb.AppendLine("...
-2
votes
1
answer
94
views
Can't understand & ~ syntaxes in a bitwise operator in Stringbuilder internal method
From the description of StringBuilder class:
private int GetReplaceBufferCapacity(int requiredCapacity)
{
// This function assumes that required capacity will be less
// than the ...
0
votes
0
answers
73
views
How to Add page number dynamically to footer in word file that create using C# StringBuilder - HTML
I created a word file using HTML - StringBuilder.Now I want to add page numbers dynamically to the footer. I tried it using counter-increment. But it is not working.If i hardcode a number inside the &...
-1
votes
1
answer
52
views
Operators in a table
There are 7 rows of output for table, how can I modify this so row 6 displays either of the three providers.
I tried something like this :
template.getProvider2() != null || template.getProvider3() != ...
0
votes
0
answers
12
views
Is ByteArrayOutputstream to string conversion from process inputstream works faster instead of using StringBuffer
I have been trying to execute commands using java. And I trying to figure a fastest way to convert process inputstream to string. On reading a lot, I found that ByteArrayOutputstream is faster. Is i t ...
0
votes
0
answers
110
views
C# - Getting "Index was out of range...Parameter name: chunkLength" error on serializing to XMLstring
Our application requires logging API requests and we are logging them in the XML format in our file system. But we're getting an Index out of range error from time to time and are unable to reproduce ...
-1
votes
1
answer
183
views
Why String Builder is returning its length zero, while returning some value of it
In below program, String buffer is working as expected, but in case of string builder, the length of String builder is zero, while it's giving me some data. So my question is, if string builder has ...
-1
votes
2
answers
45
views
Stringbuildier in loop, anything to do better?
For each x Strings the output should be in quote and each String should be separated by a comma:
For example:
input: String String1 String2
output: "String","String1","String2&...
1
vote
1
answer
63
views
How to make permutation program using StringBuilder in java?
I am willing to create a program that outputs all the possible permutations of a string.
For example:
Input
abc
Output
abc
acb
bac
bca
cab
cba
I am able to get this output when I use String in java, ...
0
votes
1
answer
29
views
CSV file export cell
So I have this app that takes listview and export to device as .csv file.
This is the code
StringBuilder sb = new StringBuilder();
for (String s : array) {
sb....
0
votes
2
answers
190
views
String builder in c# json problem with \" [duplicate]
I created an exaple to demonstrate the problem. I am trying by string builder create a json but there is one problem when the Model.Code contains the \".
If the model value contains double quote ...
0
votes
0
answers
25
views
same string but it return false while using equals method with two StringBuilder objects [duplicate]
Scanner s = new Scanner(System.in);
char[] ch = s.next().toCharArray();
Arrays.sort(ch);
StringBuilder sb = new StringBuilder();
sb.append(ch);
int n = s....
0
votes
2
answers
107
views
How to use 'REGEXP_SUBSTR' in oracle inside java code to build a dynamic sql query using StringBuilder?
I am building a dynamic query in my Java code using StringBuilder. I need to append a SELECT sub query with REGEXP_SUBSTR expression inside an IN clause. Below is what I did.
StringBuilder criteria = ...