0

I'm developing a word finder of a large text using flex. There I use a RichEditableText to show the whole text and when I find for a word I want to represent all the matching words of that text in a different colour. So I replace all the matching words with html colour changing tags as follows.

var replacedContent:String = txtRichBox.Text.replace(new RegExp(txtSearch.text,"g"), "<font color='#ff0000'>"+txtSearch.text+"</font>");

And then I set it to the RichEditableText as a HTML as follows.

txtRichBox.textFlow = TextConverter.importToFlow(replacedContent, TextConverter.TEXT_FIELD_HTML_FORMAT);

This works supper fine.

Now I have a new requirement. There the original text can be a XML. Then if I set the XML with colour changing html tags to the RichEditableText as a HTML everything crash because it takes XML tags also as HTML tags.

So I tried to replace < and > sings of the XML with &lt and &gt.

//Replace < with &lt
replacedContent:String = txtFileContent.text.replace(new RegExp("<","g"), "&lt");               

//Replace > with &gt
replacedContent = replacedContent.replace(new RegExp(">","g"), "&gt");

Then RichEditableText won't render them back to < and > sings. It shows &lt and &gt as it is.

Can anyone suggest me a solution for this?

ANJ
  • 301
  • 1
  • 2
  • 14
  • How are you setting the original text on the `txtRichBox` in the first place? – Brian May 27 '14 at 18:23
  • var displayText:String = "my xml is "; txtRichBox.text = displayText; – ANJ May 28 '14 at 03:12
  • 2
    You code is correct, only mistake is that you have to replace < with < instead of &lt Similarly replace > with > Missing Semicolon was causing all the trouble. – Sumit May 28 '14 at 07:13

0 Answers0