Re: search and count
Re: search and count
- Subject: Re: search and count
- From: Michelle Steiner <email@hidden>
- Date: Mon, 18 Nov 2002 09:50:21 -0700
On Monday, November 18, 2002, at 07:21 AM, Ruby Madraswala wrote:
1. open a text file. (Is simple text scriptable?)
2. search for a word "Data" always the first word of a line.
3. if found count number of pipes "|" in that line.
Assuming that each line ends with a carriage return...
this is line 1
line two is here
data is on line 3 with a |
data of line four contains ||
line five's | doesn't count
data for line six has a few ||| too.
| should not count.
data without a pipe shouldn't hurt.
and data in the middle with a | shouldn't count.
nor should a | with the end data
and that is the end.
set tid to text item delimiters
set the running_count to 0
set the source_file to choose file
set the file_contents to read the source_file
set the paragraph_List to the paragraphs of the file_contents
repeat with this_line in paragraph_List
if the first word of this_line is "data" then
set text item delimiters to {"|"}
set the text_items to the text items of this_line
set the pipe_count to (count of text_items) - 1
set the running_count to the running_count + the pipe_count
end if
end repeat
set text item delimiters to tid
running_count
--> 6
Unfortunately, this doesn't work:
paragraphs of the file_content whose first word is "data"
If it did, then the if-then statement could be eliminated, and only
those lines beginning with data could be considered.
--Michelle
We're not human beings having a spiritual experience.
We're spiritual beings having a human experience.
_______________________________________________
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.