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

Neatly break a paragraph into smaller strings


  • Subject: Neatly break a paragraph into smaller strings
  • From: Joseph Weaks <email@hidden>
  • Date: Wed, 25 Jun 2003 23:56:18 -0500

I'd like to improve a portion of script that receives a paragraph and breaks it into strings under a certain size for further processing. Virtually all paragraphs will be less than 1000 characters. I had a decent script snippet until I added lines to make the breaks only at certain punctuation marks. The script still works, but it sure looks ugly. (I'm sure this is the perfect example of a mini-applescripter doing things the hard/slow way.) Suggestions on a better way to do this?
Thanks,
Joe Weaks

set eachParagraph to "A paragraph over 512 characters in length with no carriage returns."
set maxParagraphLength to 420

set paragraphLength to (count eachParagraph)
set a to (paragraphLength div maxParagraphLength) + 1
set evenChunks to (paragraphLength div a) + 1

set x to 1
repeat
set y to x + evenChunks
try
repeat
if item y of eachParagraph is not in {":", ",", ".", "|","?","!",";"} then
set y to y + 1
else
exit repeat
end if
end repeat
on error
set y to x + evenChunks
end try
if y > paragraphLength then
set thisChunk to text x thru paragraphLength of eachParagraph
-- Process the chunk of text here.
exit repeat
else
set thisChunk to text x thru y of eachParagraph
-- Process the chunk of text here.
end if
set x to y + 1
end repeat
_______________________________________________
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: Script Editor 2.0 (beta II)
  • Next by Date: Tab delimited data file to FMP
  • Previous by thread: Fwd: Recipients in Mail.app [SOLVED!]
  • Next by thread: Re: Neatly break a paragraph into smaller strings
  • Index(es):
    • Date
    • Thread