2,129 questions
0
votes
1
answer
102
views
How to Replace with StringBuilder from the right
I need to replace character sequences in a string, but they are not guaranteed not to be overlapping. The rule in case of conflicts is that ( first, the longest character sequence wins, but this is ...
0
votes
0
answers
70
views
Does string interpolation StringBuilder internally? [duplicate]
Note: this is not a duplicate of the question here. That one asks about string concatenation, which is different from string interpolation.
Consider this example of string creation in C#:
var str = $&...
4
votes
4
answers
268
views
Swap the first and the last words and reverse all the middle characters
Description
Guru gave a task to his students. He gave a sentence, and the students have to swap the first and the last words and reverse all the characters between those words. Help the students ...
0
votes
0
answers
38
views
What object should I store many strings in? [duplicate]
I have a process where I must (de)tokenize payment account information. Currently, when sending a file to client with payment information (among other things), the actual payment account numbers are ...
-1
votes
3
answers
150
views
Joining Strings into final String when the items are in StringBuilder
I have read about the StringBuilder API and StringJoiner API and String.join but not sure if I have items in StringBuilder instance, which call to use to do a join with a delimiter of choice. I do not ...
0
votes
0
answers
89
views
What Culture to use with StringBuilder to preserve functionality & performance, and avoid error CA1305
What Culture should I use with StringBuilder.Append to have similar functionality to this code:
StringBuilder sb = string.empty;
string str = ...;
sb.Append($"{str}BLABLA\n");
Is it really ...
2
votes
1
answer
145
views
How can I build a string that can pass null check but will throw null pointer exception when call str.length?
I met a quite strange case in a program with jdk1.8,
that I got a null pointer exception in String.length (which is in StringBuilder.append()) method,
the exact position of the null pointer exception ...
-1
votes
1
answer
104
views
Issue related to StringBuilder in Java
The Main Issue:
Can anyone please explain me why is this IDE is saying to create a constructor for using nextLine() function?
package Practice.String_9;
import java.util.*;
public class ...
0
votes
1
answer
92
views
how the append method of StringBuilder in Java works, and why the string passed to it as a parameter doesn't create a new string object in memory
StringBuilder sb = new StringBuilder("mainWord");
sb.append("secondWord" + "thirdWord");
System.out.println(sb);
The append method here accepts a String as a parameter. ...
0
votes
2
answers
978
views
How to decode extracted text from pdf file in android kotlin? [duplicate]
I'm new to Kotlin. I am creating an application in which, after the user selects/picks a PDF file, he will see fragments of the extracted text. Unfortunately each time I read text from the PDF file it ...
0
votes
1
answer
67
views
Tried to make a program that reconstructs numbers in string from a jumble string but got index out of bound error
Reconstruct Original Digits from English
Given a string s containing an out-of-order English representation of
digits 0-9, return the digits in ascending order.
I tried the code in Java but it ...
2
votes
1
answer
208
views
Unexpected Chinese Characters in StringBuilder Char array
This is more of a curiosity question. All our software & hardware on the network are UK based. I'm using the StringBuilder.AppendLine() method to build some basic CSV data for a download on a web ...
-1
votes
1
answer
401
views
StringBuilderPool Performance Benchmark Issue
In order to gain performance on the StringBuilder operations, I tried to apply the object pooling.
But pooling the StringBuilder seems to be slower than the original usage on both net8 and net7.
What ...
0
votes
0
answers
52
views
I am having problems with <script> tag not working when it is clearly there in the html body in the browser console [duplicate]
I have a jsp file which has an "iframe" tag where my data is shown when user searches for a field. When user clicks search, my servlet gets userdata from the database and create html page ...
1
vote
2
answers
80
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
107
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
262
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
222
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
84
views
How to add all the elements of an int[] to a StringBuilder using a 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:
StringBuilder res = new StringBuilder();
Arrays.stream(brr).forEach(res::append);
I want ...
0
votes
4
answers
98
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(...
-2
votes
1
answer
100
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 ...
1
vote
0
answers
43
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
0
answers
204
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
150
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
54
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
75
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
53
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
2
answers
77
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
224
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
41
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()
{
...
-1
votes
1
answer
919
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
74
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
132
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
156
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
75
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
339
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
547
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
222
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 ...
0
votes
1
answer
1k
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
71
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
84
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
547
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
279
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);
...
-3
votes
3
answers
1k
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
111
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
87
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
477
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
120
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
109
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
101
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 ...