Re: getting chunks of text
Re: getting chunks of text
- Subject: Re: getting chunks of text
- From: Michelle Steiner <email@hidden>
- Date: Wed, 16 Mar 2005 22:17:19 -0700
On Mar 16, 2005, at 8:40 PM, Scott Haneda wrote:
Given a string of length unknown, I need to chop it up to less than 256
characters, however, I do not want to chop a word in half, so scan
backwards
to the first space before 256 chars. Not to worried about what would
happen
when running into punctuation and such.
I need a result set that I can repeat through, thanks.
I'm missing something here; do you need help with a script, or do you
simply want text to work on? If the latter, just copy something from a
news article on a web site, or something like that.
If the former, try this:
set foo to sometext --replace "sometext" with real text
if length of foo is greater than 256 then
set bar to text 1 through 256 of foo
repeat until the last character of bar is space
set bar to text 1 through -2 of bar
end repeat
set bar to text 1 through -2 of bar
else
set bar to foo
end if
The above script assumes that if the original text is 256 characters or
less, it doesn't matter whether it ends with a word.
Alternatively, if you don't mind stripping punctuation in the middle of
the text, try this:
if length of foo is greater than 256 then
set bar to text 1 through 256 of foo
if character 257 of foo is not space then
set bar to words 1 through -2 of bar
set text item delimiters to space
set bar to bar as text
set text item delimiters to ""
end if
else
set bar to foo
end if
bar
--
Tubal Litigation: Suing because of a misconception
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden