How do you escape the angle brackets in rich text?

I saw this question but this example didn’t really require a real answer.

Let’s assume escaping worked the same as HTML. Then I could do this

 string msg = @"Insert your message here.

 You can use rich text like

       this word is <color=red>red</color>

 which will produce

       this this is <color=red>red</color>";

 GUI.Label(msg, someStyleWithRichTextTrue);

Which when displayed the first color pair would show the codes and the second the result.

So, is there a way to escape the angle brackets in rich text?

Put something right after the opening angle bracket:

this word is <<b></b>color=red>red<<b></b>/color>

There still doesn’t seem to be a way to escape the angle characters in rich text. I ended up just replacing every ‘<’ with this unicode character: Unicode Character 'LEFT ANGLE BRACKET' (U+3008) and every ‘>’ with this unicode character: Unicode Character 'RIGHT ANGLE BRACKET' (U+3009)

I found out that this is working too:

str.Replace("<", "<\u200B")

The \u200B is a invisible unicode space character and it will prevent that the richtext parser of Unity is able to interpret it as a valid richtext tag, which makes it displayed as raw text.

Here are the first three google results, all of which answer your question:

1.) The RTF Cookbook: Characters, Escapes, and Character Commands
2.) ASCII-RTF Reference Table
3.) The full RTF specification, with the Unicode section covering escape characters