• 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
Breaking up a long string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Breaking up a long string


  • Subject: Breaking up a long string
  • From: Joseph Weaks <email@hidden>
  • Date: Wed, 18 Jun 2003 23:48:35 -0500

Any suggestions on a better way to do this?

set thisParagraph to "A really long paragraph that I need to break into longer chunks..."
set maxParagraphLength to 400

repeat with x from 1 to (length of thisParagraph) by maxParagraphLength
try
set thisChunk to (characters x thru (x + maxParagraphLength)) of thisParagraph as string
on error
set thisChunk to (characters x thru (length of eachParagraph)) of thisParagraph as string
end try

-- do stuff with thisChunk

end repeat

Thanks,
Joe

P.S. The "as string" was causing the app that calls this script to crash. It took me awhile to find this culprit, which was happening because I had earlier changed Applescript's tid WITHOUT restoring previous value. I thought I'd give it a try as per the recent discussion. No more. I'm a born again save and restorer. The argument that it adds alot of wasted code doesn't resonate with me, since I'd have to set the tid's before EVERY list/string coercion if I stayed with that approach. (ie. the above code snippet would have two extra lines setting the tid's to "")
_______________________________________________
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: Breaking up a long string
      • From: John Delacour <email@hidden>
References: 
 >key,value pairs (From: "Steven D. Majewski" <email@hidden>)

  • Prev by Date: Re: key,value pairs
  • Next by Date: Re: AppleScript Timed Events
  • Previous by thread: Re: key,value pairs
  • Next by thread: Re: Breaking up a long string
  • Index(es):
    • Date
    • Thread