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
JavaBot
JavaBot15mo ago
This post has been reserved for your question.
Hey @bambyzas! Please use /close or the Close 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.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st15mo ago
Can you show both versions? ideally in Discord using a code block
bambizas19
bambizas19OP15mo ago
Sure. Ill try fuk me
bambizas19
bambizas19OP15mo ago
No description
dan1st
dan1st15mo ago
looks like the message is too long ok so append adds something to the existing StringBuilder so you are modifying your StringBuilder
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
dan1st
dan1st15mo ago
adding stuff to it
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
dan1st
dan1st15mo ago
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
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
dan1st
dan1st15mo ago
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
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
dan1st
dan1st15mo ago
ah ok
bambizas19
bambizas19OP15mo ago
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
dan1st
dan1st15mo ago
Don't you only want to add something at the beginning?
bambizas19
bambizas19OP15mo ago
no. adding at the beggining wouldnt always work
tjoener
tjoener15mo ago
SOODODDRDRRASOODODDRDRRA That's what I get as output Is that correct?
JavaBot
JavaBot15mo ago
💤 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.

Did you find this page helpful?