How to use StringBuilder to concat strings propperly?
Hey guys. I was wondering if smb could help optimize my code: https://appp.me/3vN6Ka
I was thinking about using StringBuilder when constructing
currentWord
, but the concatenation using it was very weird and not as expected. I was using it like this: currentWord=stringBuilder.append(element2).append(element).append(currentWord).toString;)
and in other case the other way around. But it gave me too much repeated letters (unlike + sign concat). Can smb help me out?
Im sorry Im using pastebin, its because I couldnt send full message, because I was getting an error "U cant message this person, bc you two dont share the same servers".Pastebin Online - AppDevTools
Pastes text or code for online public viewing via a share link with syntax highlighting and an optional expiration period. Supports over 170 programming languages.
18 Replies
⌛
This post has been reserved for your question.
Hey @bambyzas! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Can you show both versions?
ideally in Discord using a code block
Sure. Ill try
fuk me

looks like the message is too long
ok so
append
adds something to the existing StringBuilder
so you are modifying your StringBuilder
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
adding stuff to it
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
and always adding the current word
and saving the result into the current word
well I think they don't want String concatenation
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
if you want to optimize it save all words to a list and then iterate over the list in reverse order
and add all of it to a
StringBuilder
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
ah ok
wait. what. these loops order the letter pairs in the order i need. i cant just dump these pairs in random order into a list
Don't you only want to add something at the beginning?
no. adding at the beggining wouldnt always work
SOODODDRDRRASOODODDRDRRA
That's what I get as output
Is that correct?💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.