Search code examples
user-interfacec#-4.0text-formattingcolorsxna-4.0

Formatting Text in C# with XNA


I'm currently trying to make a TextBox for my GUI with XNA, and I was wondering how could I find tagged text in a string.
For instanceI have this kind of text:

Hey there, I was <r>going to</r> the <b>Mall</b> today!

So the <r> tag would represent red text and the <b> tag would represent blue text.
And I want to know exactly where the red text starts and where the blue text starts so I could render them separately.
Do you have any suggestion what to do about it, and what to use for doing that?

Thanks in advance.


Solution

  • Well you could just parse the line and when you reach a set a color property of your text so that it will now render blue but it will have to be a separate render call or else the whole string will turn blue. So if you make a new string when you come upon a tag then set the color property then render that string then that should work.