text color part 2

Mark Wieder mwieder at ahsoftware.net
Tue Nov 22 21:51:10 EST 2011


Tuesday, November 22, 2011, 5:22:51 PM, you wrote:

> Mark,

> Thanks for the suggestion.  I've typically done just that to
> color text.  The problem is, in this case, the field contains
> plaintext that is actual html, and I need to be able to view it
> without it disappearing and modifying other text.  For example, a
> search could be done on, say, "<font" and I want it to find all of
> this occurrences and color them to make them stand out.  Mike's
> suggestion got me to an answer, and we both posted working solutions.

Fair enough, but I still would opt for the replace command for speed
rather than a repeat loop. A couple of extra lines allows you to have
html tags embedded in the text itself. Just a thought.

on mouseUp
    local tText
    local tStrReplace
    local tSearchString
    put the htmltext of field "Original" into tText
    put the htmltext of field "SearchField" into tSearchString
    -- remove the "<p>" and "</p>" strings
    delete char 1 to 3 of tSearchString
    delete char -4 to -1 of tSearchString
    put "<font color=" & quote & "red" & quote & ">" \
            & tSearchString & \
            "</font>" into tStrReplace
    replace tSearchString with tStrReplace in tText
    set the htmltext of field "Results" to tText
end mouseUp

-Mark Wieder
 mwieder at ahsoftware.net

More information about the Use-livecode mailing list