I'm trying to replace a set of characters within a string. The string may or may not have any data to change. The string is marked up in a way that allows for it to change it's color from a set of characters. The string can reset it's formatting to default by using a defined set of characters.
This setup is very much like the ECMA-48 standard used on LINUX consoles for colors and other special effects.
Where one string could be ^0Black^1Red^2Green^3Yellow^4Blue^5Purple^6Cyan^7White
Producing the following HTML:
<span style="color: #000">Black</span><span style="color: #F00">Red</span><span style="color: #0F0">Green</span><span style="color: #FF0">Yellow</span><span style="color: #00F">Blue</span><span style="color: #F0F">Purple</span><span style="color: #0FF">Cyan</span><span style="color: #FFF">White</span>
Another string (^1Error^8: ^3User Error
) could also produce:
<span style="color: #F00">Error</span>: <span style="color: #FF0">User Error</span>
You might of noticed the ^8
part of that string resets the color for that part of the string.
What's the best way to go about parsing these kinds of strings?