Re: trying to make a list of numbers
Re: trying to make a list of numbers
- Subject: Re: trying to make a list of numbers
- From: Emmanuel <email@hidden>
- Date: Fri, 9 Jul 2004 14:22:49 +0200
At 7:06 PM -0700 08/07/04, Richard Allaway wrote:
>
set theText to "30.14
>
-0.25
>
-0.82
>
30.13
>
30.68
>
29.95
>
19.13
>
34.19" as Unicode text
>
log every word of theText
As you have been told, you have to use "paragraphs" instead of "words" to split correctly the string.
Unfortunately, you will get a list of strings:
{"30.14", etc.}
rather than a list of numbers:
{30.14, etc.}
Fortunately, you can coerce a string into a number:
set theString to "30.14"
set theNumber to theString as number
-- 30.14
Unfortunately you cannot coerce a list of strings into numbers in one instruction, you have to use a loop, which may be slow.
Fortunately, Satimage.osax handles the coercion from a list of strings into a packed array of numbers (a private type named "array of real"), and also from "array of real" into a standard list of numbers:
set theListOfStrings to {"30.14", etc.}
set theListOfNumbers to (theListOfStrings as array of real) as list of real
-- {30.14, etc.}
Emmanuel
_______________________________________________
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.