Remove Specified Character From String

sparklyllama

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?

Baby

| 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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Remove the Nth specified character from a line

From Java

Remove the last character from a string

From Dev

(swift) remove "\" character from string?

From Dev

Remove � Special Character from String

From Java

Swift - Remove " character from string

From Dev

Remove first character from a string

From Dev

How to remove a character from a string

From Dev

Remove � Special Character from String

From Dev

Remove specified pattern from string in R

From Dev

Remove specified pattern from string in R

From Dev

Remove a substring from a string starting from a character

From Dev

R regex: remove times from character string

From Java

How to remove the last character from a string?

From Dev

Regex to remove newline character from string

From Dev

Python / Remove special character from string

From Dev

R remove first character from string

From Dev

How to remove the leading character from a string in smalltalk

From Dev

remove all special character from string java

From Dev

How to remove character containing String from Python?

From Dev

Android How to Remove( " )Character from String

From Dev

Remove last character from string in sql plus

From Dev

Remove first character from a string if it is 0

From Dev

Remove a particular character from the end of each string

From Dev

Android remove string from start to perticular character

From Dev

remove_if last character from a string

From Dev

How to remove ↵ character from JS string

From Dev

Remove character from string if its not in a list...?

From Dev

How to remove the  character from a string in java?

From Dev

Remove first character from string Django template

Related Related

HotTag

Archive