Reputation: 126
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.
Upvotes: 0
Views: 67
Reputation: 13
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);
}
Upvotes: 1