• 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: Neatly break a paragraph into smaller strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Neatly break a paragraph into smaller strings


  • Subject: Re: Neatly break a paragraph into smaller strings
  • From: Nigel Garvey <email@hidden>
  • Date: Fri, 27 Jun 2003 21:16:39 +0100

In my message of Friday, 27 June 2003 19:49:55, I wrote:

> to chopText of s below m
[...]
> -- Truncate this segment if a suitable cut's found
> if c < m then
> set m to m - c
> set subS to subS's text 1 thru m
> end if
> {subS} & (chopText of (s's text (m + 1) thru -1) below m)
> end chopText

Oops! Can't fool around with m and get away with it. Here's a repaired
version:

to chopText of s below m
if m is greater than or equal to (count s) then return {s}
set subS to s's text 1 thru m
set c to m
set t to text item delimiters
-- Search for these particular punctuations followed by spaces
repeat with d in {": ", ", ", ". ", "| ", "? ", "! ", "; "}
set text item delimiters to d's contents
tell (count subS's text item -1)
if it is less than c then set c to it
end tell
end repeat
-- If no such punctuation in the second half of this segment,
-- find the last space instead
if c > (m div 2) then
set text item delimiters to space
set c to (count subS's text item -1)
end if
set text item delimiters to t
-- Truncate this segment if a suitable cut's found
if c < m then set subS to subS's text 1 thru (m - c)
{subS} & (chopText of (s's text (m - c + 1) thru -1) below m)
end chopText


set testString to "This is a test; this is a jest: This is a nest. Is
this a pest? Give it a rest!"

chopText of testString below 70
--> {"This is a test; this is a jest: This is a nest. Is this a pest?
", "Give it a rest!"}

NG
_______________________________________________
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.

  • Follow-Ups:
    • Re: Neatly break a paragraph into smaller strings
      • From: Joseph Weaks <email@hidden>
  • Prev by Date: long question about how to handle timeouts (AS techniques & HIG)
  • Next by Date: Re: Strange problem with text item delimiters
  • Previous by thread: Re: Neatly break a paragraph into smaller strings
  • Next by thread: Re: Neatly break a paragraph into smaller strings
  • Index(es):
    • Date
    • Thread