news
About Elegant Chaos
info
About me and my friends
people
Software from Elegant Chaos
software
Other stuff...
stuff

UL_LineOffset

Revision 1
Revised on 19/03/95 19:08

Description

Return the first line in which the given key occurs. Takes the key to find, and the text to find it in.

This routine works like Hypercard's built-in Offset function, except that it returns the line number where the key was found, instead of the character number.


Code

function UL_LineOffset key,text
  -- get the offset of the key in characters
  get offset(key,text)
  
  if it is 0 then
    -- the key isn't present, so return zero as the result
    return 0
    
  else
    -- delete everything after the first character of the key
    delete char it+1 to length(text) of text
    
    -- replace what was the first character of the key with
    -- something that definitely isn't a return character
    put "x" into last char of text
    
    -- return the number of lines in what's left of the text
    -- since the last line of the text now contains the key,
    -- this value gives us the line number where the key was found
    return the number of lines in text
  end if
end UL_LineOffset