Re: Tex-Edit string manipulation.
Re: Tex-Edit string manipulation.
- Subject: Re: Tex-Edit string manipulation.
- From: Rachel <email@hidden>
- Date: Sun, 26 Aug 2001 18:16:28 -0600
OK, here is the masterpiece.
Thanks, Marc for shoving me in the right direction. Feel free to op[timize
this script and return it to me.
PS:Are we allowed attachments on this list?
Rachel
******************
set theMargin to 12
tell window 1 of application "Tex-Edit Plus"
set someSpaces to ""
repeat with i from 1 to theMargin
set someSpaces to someSpaces & " "
end repeat
strip removing leading spaces
set x to ""
repeat with i from 1 to (count lines)
set theText to line i
if character 1 of theText is return then --paragraph break
set x to ""
set theDiff to ""
set y to ""
else
set x to word 1 of theText
try
set theDiff to text 1 thru (theMargin - (length of x)) of
someSpaces
set y to text from word 2 to word -1 of theText
on error -- line will be only first word
set theDiff to ""
set y to ""
end try
end if
set theText to x & theDiff & y & return
set line i to theText
end repeat
end tell
*******************
Entity Marc K. Myers spoke thus:
>
Rachel wrote:
>
>
>
> Marc:
>
> this looks like it should work, but I keep getting an error: CANT GET
>
> CHARACTER 1 OF "".
>
> I will play with it at my leisure, but I thought every line had at least a
>
> CR. Ideas?
>
> Rachel
>
>
>
> Entity Marc K. Myers spoke thus:
>
>> I'd do it this way (it assumes that the text should start in column 26):
>
>>
>
>> set someSpaces to " "
>
>> tell window 1 of application "Tex-Edit Plus"
>
>> repeat with i from 1 to (count paragraphs)
>
>> set theText to paragraph i
>
>> set x to word 1 of theText
>
>> set y to text from word 2 to word -1 of theText
>
>> set theDiff to 25 - (length of x)
>
>> set theText to x & (text 1 thru theDiff of someSpaces) & y
>
>> set paragraph i to theText
>
>> end repeat
>
>> end tell
>
>
Every line _does_ have a carriage return, but I suspect that you have
>
lines that contain _only_ a carriage return. Put in code to filter out
>
those lines and you should be OK. (Hint: if length of paragraph i > 0
>
then process else skip the paragraph.)
>
>
Marc K. Myers <email@hidden>
>
http://AppleScriptsToGo.com
>
4020 W.220th St.
>
Fairview Park, OH 44126
>
(440) 331-1074
>
>
[8/24/01 4:47:56 PM]
>
_______________________________________________
>
applescript-users mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/applescript-users