This content has been marked as final. Show 10 replies
You could try the offset() function instead of searching char by char.
However, this will require that you start with a duplicate of your
original string since offset will only find the first match (match in
your duplicate, get the first char from the offset function, delete from
char 1 to offset + matching_string_length, keep a running total of chars
deleted, repeat until offset returns 0)
Or you could use a regular expression and the PRegEx xtra (free) to find
a match and obtain the offset
By far the fastest text searching xtra is pRegEx. It is not terribly
easy to use if you are not familiar with regular expressions, but that
is the fastest way to do it. And it's free.
Here's a handler that uses pRegEx to get the match positions:
on mGetMatchPositions aString, aMatch
lString = [aString]
lReturn = 
if PRegEx_SearchBegin(lString, aMatch, "g") > 0 then
repeat while (pRegEx_SearchContinue() > 0)
lReturn.append( PRegEx_GetPos() )
From the message window:
t = "This is a string of text"
put mGetMatches(t, "t")
-- [1, 12, 21, 24]
The returned list indicates the position of the /last/ character in a
match. Since you provide the match string, you know how long it is, so
you can iterate through the list returned subtracting the length of the
string matched and setting the colour of this chunk
on mSetColour aMember, sMatch, aColour
if aMember.type <> #text then exit
if stringP(sMatch) = 0 then exit
if ilk(aColour, #color) = 0 then exit
lMatched = mGetMatchPositions( aMember.text, sMatch )
len = length(sMatch)
repeat with aPosition in lMatched
aMember.char[(aPosition - len + 1)..aPosition].color = aColour
Hard to answer without knowing:
- How many 'special words' do you have, and could they be defined using a pattern or do they require a 'dictionary lookup'.
- Is this for Shockwave or Projector?
- Is the text dynamic or can 'pre markup' the text
Thanks for all your snippets Sean, Im all ready to give pReg a try!
While I all have you here, couldnt find any thread about this...
Is it possible to make the projector associated application for a extension. The lingo stuff Im worried about.
I dont have buddy api...
edit: let me make that clearer... so projector reads the clicked file when launched.
> Is it possible to make the projector associated application for a extension.
> I dont have buddy api...
Yes. You'll need Buddy API (or similar) for registry access. Check out:
Since it is a projector, definitely look at PregEx Xtra (its fast). Have a look at the PRegEx_ReplaceExec method - it will let you make callback on each match. So you would use a regular expression to isolate potential matches, and then a lookup on each match to confirm it is a key word -- Something like this:
TextMember = member("foo") -- this is a text member containing the text to process
Are there any good benefits by converting to html and back?
Preg is working great now, very smooth
Looked through the docs and cant find any info how to detect for ex */
like "((*/)|(/*))" if it was easy :)
> Preg is working great now, very smooth
> Looked through the docs and cant find any info how to detect for ex */
> like "((*/)|(/*))" if it was easy :)
The xtra has a method for escaping special/reserved characters: