Re: strings, again and again
Re: strings, again and again
- Subject: Re: strings, again and again
- From: "Gary (Lists)" <email@hidden>
- Date: Sun, 03 Feb 2008 06:02:45 -0500
- Thread-topic: strings, again and again
"Justin Laden" wrote:
> Can anyone tell me why this just populates the target list with
> "empty"--it doesn't pull the string I need.
You're not using the result of 'find text' properly, basically. We'll fix
that, below. I don't think that's the primary error, however.
Even if that worked (you had it, but commented it out), you would get errors
because of the way you are trying to add to a list. We'll fix that, below,
too.
Kurt made some useful notes about better use of the 'on error' handler. I'd
take his advice there.
As for your script...
> repeat with i from 1 to (z)
I'd use (count descriptionRange) instead of z (unless you've done that
before, in unpublished code.) My script, below, will use 'count'.
> try
> set firstPull to find text "^[a-zA-Z][0-9]{4}" in item i of
> descriptionRange with regexp
>
> --set refinedData to matchResult of firstPull
That *is* what you want. Why'd you comment it out? ;)
That's the correct record label from the result you'd get.
I think you had another error, on the next line, and so probably tried to
change this, which made things worse.
> set item i of jobNumRange to firstPull
This is no good. You will get an error here, because there is no item 1 (i)
of jobNumRange, or 2 (i), or ...
(Kurt's note about 'on error...' would help here. You'd know that you were
getting an error AND which one.)
In order to add things to a list -- even an initially empty list -- use
this:
copy someValue to the end of someList
> on error
>
> set item i of jobNumRange to "empty"
That's the same problem as directly above.
Lookit:
set mylist to {}
set item 1 of mylist to "hello"
--> ERROR: Can't set item 1 of mylist to "hello"
copy "hello" to end of mylist
--> {"hello"}
> end try
>
> end repeat
Here's a version of your script that works. I had to guess what you might
have in 'descriptionRange', since you didn't show that (you should, it would
help.)
set descriptionRange to {"a1234", "b5678", "c9012", "d3456"}
set jobNumRange to {}
repeat with i from 1 to (count descriptionRange)
try
set firstPull to find text "^[a-z][0-9]{4}" in item i of
descriptionRange with regexp
-- PROBLEM: set item i of jobNumRange to firstPull
-- That's not how you add to a list.
-- Use:
copy matchResult of firstPull to end of jobNumRange
on error _msg number _enum
copy "empty" to end of jobNumRange
-- Same problem as above.
end try
end repeat
jobNumRange
--> {"a1234", "b5678", "c9012", "d3456"}
If that's kind of what you have in 'descriptionRange', then this works.
That is, 'descriptionRange' should be a list of strings, based on what it
seems like you're doing.
You had it. You just got fumbled up a bit on the list thing, which is what I
think was your script's primary error (until you commented the 'matchResult'
line.)
HTH,
--
Gary
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden