• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: trying to make a list of numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >trying to make a list of numbers (From: Richard Allaway <email@hidden>)

  • Prev by Date: Call AppleScript from remote server. How?
  • Next by Date: Re: Changing screen resolutions - updated
  • Previous by thread: Re: trying to make a list of numbers
  • Next by thread: Applet Identifier for Mac OS X server registration
  • Index(es):
    • Date
    • Thread