Re: Newbie. How to find numbers after....
Re: Newbie. How to find numbers after....
- Subject: Re: Newbie. How to find numbers after....
- From: Nigel Garvey <email@hidden>
- Date: Mon, 28 Jan 2002 05:38:36 +0000
Steen wrote on Mon, 28 Jan 2002 01:56:09 +0100:
>
This time I wish to find numbers in some text.
>
But it is number everywhere in the text.
>
Therefore I only wish to look for numbers after WELCOME in the text.
>
>
My plan was to find the line containing WELCOME.
>
Then look for numbers to the end of the text.
[...]
>
Set someText to "I live in Norway. The number is 23.
>
I look out of my window, it is snowing. Jada jada 243
>
>
WELCOME
>
It is after hello I wish to look up for numbers.
>
23 456 23 3 and 12345 is not my numbers.
>
we got lot of text here, but I think I end for now."
I'd use "WELCOME" as a text item delimiter and extract the relevant part
of the text. Then it would be a matter of looking at each word in turn.
Applescript has some idiosyncratic ways of deciding what's a word and
what isn't, but for pure numbers written in the style of your own
language, you should be OK. However, I'm not sure I'd want to use this on
extremely long texts...:
set someText to "I live in Norway. The number is 23.
I look out of my window, it is snowing. Jada jada 243
WELCOME
It is after hello I wish to look up for numbers.
23 456 23 3 and 12345 is not my numbers.
we got lot of text here, but I think I end for now."
set AppleScript's text item delimiters to {"WELCOME"}
set relevantText to text from text item 2 to -1 of someText
set AppleScript's text item delimiters to {""}
set searchWords to the words of relevantText
set numberList to {}
repeat with thisWord in searchWords
try
set the end of numberList to thisWord as number
on error
-- This word's not a number - ignore it
end try
end repeat
numberList
--> {23, 456, 23, 3, 12345}
NG