Re: Finding a location in a text file
Re: Finding a location in a text file
- Subject: Re: Finding a location in a text file
- From: Emmanuel <email@hidden>
- Date: Sat, 19 Nov 2005 15:25:15 +0100
At 6:50 AM -0600 11/19/05, Jim Brandt wrote:
I'm trying to write a script to do some text cleanup in Tex-Edit Plus.
What I need to do is locate a certain word imbedded in a line several
lines down from the top of a document. I then want to delete all of the
text from the beginning of the document to just before that word.
i.e.
for the three line above, if I wanted to delete from "What" in line one
to the word "want" in line two, the result would be:
want to delete all of the
text from the beginning of the document to just before that word.
My problem is counting characters.
In Tex-Edit Plus, I can search for "want", and it will correctly search
for and highlight it as the selection.
tell application "Tex-Edit Plus"
tell window 1
search looking for "want"
set x to line offset of selection
I have now located the line that my desired text is on.
What I can't figure out is how to count the characters on
that line (or from the beginning of the document, either
would work) in order to delete up to that point.
Any suggestions?
This is very easy in Smile, mostly because you can program in an
interactive fashion (the script in a window, the text in the other,
the result in the Console), but usually users of Tex-Edit are
reluctant to use Smile, which is slightly less comfortable as a text
editor.
In Smile:
find text "want" in window 2
will return a record with the location of the hit:
{matchPos:2443, matchLen:4, matchResult:"want"}
(matchLen and matchResult look useless, they are useful when you
search Regular Expressions)
Emmanuel
_______________________________________________
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