In my Text Rendering system for my game, I've implemented support for coloured words. So, if I want to render a sentence with the first word in red, and the other words in white, I can do something like this:
"|3Hello |1there Steven!"
When the string is rendered, it searches for a |
character, and then looks at the number afterwards, which corresponds to a certain colour, (3 = red, 1 = white) and then it colours the rest of the string in that colour.
I want to be able to remove the |
character as well as the number after it.
When it looks at the message and sees the |3
, I want it to set the colour to red, and then remove the |3
. If I use a method that replaces all the |
followed by a number after it, when it comes to the part with |1
, it won't set the colour to white because the |1
isn't in the message anymore.
How can I do this?
|
is a special character so you must escape it
How about this? (assuming there is only one number after the '|'
)
str=str.substring(0,str.indexOf("|")+2).replaceAll("[|]\\d+", "")+str.substring(str.indexOf("|")+2);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments