Re: Detect if third word in string contains a number
Re: Detect if third word in string contains a number
- Subject: Re: Detect if third word in string contains a number
- From: Nigel Garvey <email@hidden>
- Date: Thu, 10 May 2012 15:20:09 +0100
In my message of Thu, 10 May 2012 15:10:20 +0100, I wrote:
> -- Identify which word's the number.
> set numberWordNumber to 1
> repeat with thisWord in _selection's words
> if (thisWord is in "363534332313029282726252422120191817161514110")
>then exit repeat
> set numberWordNumber to numberWordNumber + 1
> end repeat
> -- Act accordingly.
> if (numberWordNumber is 1) then
> -- The first word's the number.
> else if (numberWordNumber is 2) then
> -- The second word's the number.
> else if (numberWordNumber is 3) then
> -- The third word's the number.
> set word1 to word 1 of _selection
> if (word1 is in "I II III") then set the clipboard to ((count
word1) as
>text) & space & text from word 2 to -1 of _selection
> else --> numberWordNumber = 0 or numberWordNumber > 3.
> error "None of the first three words of the selection is a number."
> end if
I changed the code for identifying the number word just before posting
and forgot to update the last comment in the script. To forestall
anxiety and confusion, here's a corrected version:
-- Identify which word's the number.
set numberWordNumber to 1
repeat with thisWord in _selection's words
if (thisWord is in "363534332313029282726252422120191817161514110") then exit repeat
set numberWordNumber to numberWordNumber + 1
end repeat
-- Act accordingly.
if (numberWordNumber is 1) then
-- The first word's the number.
else if (numberWordNumber is 2) then
-- The second word's the number.
else if (numberWordNumber is 3) then
-- The third word's the number.
set word1 to word 1 of _selection
if (word1 is in "I II III") then set the clipboard to ((count word1) as text) & space & text from word 2 to -1 of _selection
else -- (numberWordNumber > 3).
error "None of the first three words of the selection is a number."
end if
NG
_______________________________________________
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