How to create a hyperlink within a text field?

Peter M. Brigham pmbrig at gmail.com
Fri Feb 5 08:53:22 EST 2016


On Feb 3, 2016, at 9:20 PM, Kay C Lan wrote:

>> The second is to get the lineoffsets
>> of the link text and scroll to the second occurrence of it.
> 
> 
> With lineOffset you can guarantee that it will be the first line found by
> determining how long your TOC is or on what line the 'body' of your
> information starts within your field and using this as the <linesToSkip>
> parameter.
> 
> select line (lineOffset(tHeading, fld "Interesting stuf", 27) + 3) of fld
> "interesting stuff"

I use the following to get all the lineoffsets of a string in a container. This kind of situation is just one of the useful applications of the function. In this case item 2 of lineoffsets(…) does the job. If you pass true for matchWhole when calling it, then you will only get whole titles, which will work as long as you don't have two identical chapter titles.

function lineOffsets str, pContainer, matchWhole
   -- returns a comma-delimited list of all the lineOffsets of str
   --    in pContainer
   -- if matchWhole = true then only whole lines are located
   --    else finds line matches everywhere str is part of a line in pContainer
   -- duplicates are stripped out
   -- note: to get the last lineOffset of a string in a container (often useful)
   --    use "item -1 of lineOffsets(...)"
   -- by Peter M. Brigham, pmbrig at gmail.com — freeware
   -- requires offsets()
   
   if matchWhole = empty then put false into matchWhole
   put offsets(str,pContainer) into offList
   if offList = "0" then return "0"
   repeat for each item i in offList
      put the number of lines of (char 1 to i of pContainer) into lineNbr
      if matchWhole then
         if line lineNbr of pContainer <> str then next repeat
      end if
      put 1 into A[lineNbr]
      -- using an array avoids duplicates
   end repeat
   put the keys of A into lineList
   sort lines of lineList ascending numeric
   replace cr with comma in lineList
   return lineList
end lineOffsets

function offsets str, pContainer
   -- returns a comma-delimited list of all the offsets of str in pContainer
   -- returns 0 if not found
   -- note: offsets("xx","xxxxxx") returns "1,3,5" not "1,2,3,4,5"
   --     ie, overlapping offsets are not counted
   -- note: to get the last occurrence of a string in a container (often useful)
   --     use "item -1 of offsets(...)"
   -- by Peter M. Brigham, pmbrig at gmail.com — freeware
   
   if str is not in pContainer then return 0
   put 0 into startPoint
   repeat
      put offset(str,pContainer,startPoint) into thisOffset
      if thisOffset = 0 then exit repeat
      add thisOffset to startPoint
      put startPoint & comma after offsetList
      add length(str)-1 to startPoint
   end repeat
   return item 1 to -1 of offsetList -- delete trailing comma
end offsets

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig





More information about the use-livecode mailing list