• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Choose from list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Choose from list


  • Subject: Re: Choose from list
  • From: Arthur J Knapp <email@hidden>
  • Date: Tue, 07 May 2002 09:49:39 -0400

> Date: Tue, 7 May 2002 01:10:05 +0100
> Subject: Re: Choose from list

>> Hmmm....does anyone know if it's possible to get offsets in terms of
>> paragraphs, instead of characters?

One can adopt the binary search that I posted earlier to working directly
with paragraphs:


on OrdinalParagraph(str, sub)

set sub to sub's paragraph 1 --> removes any last return

tell str to if it contains sub then

set l to 1
set r to count paragraphs in it

repeat until paragraph l = sub

set m to (l + r) div 2

if paragraphs l thru m contains sub then

set r to m
else
set l to m + 1

end if
end repeat

return l

end if

return 0

end OrdinalParagraph


on OrdinalContainingParagraph(str, sub)
(*
* Find paragraph containing sub
*)

set sub to sub's paragraph 1 --> must not contain a return

tell str to if it contains sub then

set l to 1
set r to count paragraphs in it

repeat until paragraph l contains sub

set m to (l + r) div 2

if (text (paragraph l) thru (paragraph m)) contains sub then

set r to m
else
set l to m + 1

end if
end repeat

return l

end if

return 0

end OrdinalContainingParagraph



{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www.goodbuddy.net/budco/sware/imscripts.htm>
on error number -128
end try
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: What happened to "file"?
  • Next by Date: Re: Setting Default Browser in OS X
  • Previous by thread: Re: Choose from list
  • Next by thread: Re: Choose from list
  • Index(es):
    • Date
    • Thread