0

I have a string made up of several commas, and also several color formatting codes in the form of the '§' symbol and then a character (ex. "§a§6Text, here" should become "Text here). I want to remove all of the commas, but also all of the color formatting. I used this code, but when it runs, it doesn't end up removing the formatting, it becomes some sort of mystery character that changes depending on which text editor I open it in ("�" in notepad/++, "�f�f�" in Excel).

I'm running Java 11, and I checked my RegEx in notepad++, it seems to work. As of now, my code successfully removes commas, but not the color formatting.

for (String entry : lineEntries) {
                String entryx = entry.replace(",", "");
                entryx = entryx.replace("§.", "");
                refinedEntries.add(entryx);
            }

If I were to input "§f§f§6Spicy,Special", I would want it to return "SpicySpecial"

Edit: fixed a separate error that still was a pretty big deal, but did not fix the problem.

1 Answer 1

1

The code isn't working because in

               String entryx = entry.replace(",", "");

you are removing every comma from entry and it'll return the result in entryx and after you should use the result of the first operation which is entryx to remove every special symbol So your code should be like this

for (String entry : lineEntries) {
            String entryx = entry.replace(",", "");
            entryx = entryx.replace("§", "");
            refinedEntries.add(entryx);
        }
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I tried changing my code to this, and I can see how that would be a big error. However, this still did not fix the problem with removing the color formatting. Any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.