• 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: "+" and "-" are numbers.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "+" and "-" are numbers.


  • Subject: Re: "+" and "-" are numbers.
  • From: "Arthur J. Knapp" <email@hidden>
  • Date: Fri, 02 Aug 2002 13:42:36 -0400

> Date: Fri, 2 Aug 2002 10:54:41 -0400
> Subject: "+" and "-" are numbers.
> From: Paul Skinner <email@hidden>

> "+" as number
> -->0

> "-" as number
> -->0

> Why?
Bug! ;-)

It is most likely a parsing problem related to the fact that a
"number" can start with a plus or minus sign. Sometimes, this
can be useful:

(* Not fully tested!!!
*
* replace ` with line-continuation character, option-L
*)
on ExtractNumber(s)
(*
* Find the first "number" that can be located
* in s.
*)
if ("0" is in s) or ("1" is in s) or `
("2" is in s) or ("3" is in s) or `
("4" is in s) or ("5" is in s) or `
("6" is in s) or ("7" is in s) or `
("8" is in s) or ("9" is in s) then

set x to 1
repeat until s's character x is in "0123456789"
set x to x + 1
end repeat

if (x > 1) and (s's character (x - 1) = "-") then `
set x to x - 1

set n to (s's character x) as number
repeat with y from x to s's length
try
set n to (s's text x thru y) as number
on error
return n
end try
end repeat

else
return missing value
end if
end ExtractNumber

ExtractNumber("abc 123.456 def") --> 123.456
ExtractNumber("abc +123.456 def") --> 123.456
ExtractNumber("abc -123.456 def") --> -123.456

(* Not working right...
*)
ExtractNumber("abc 1.0E+9 def") --> 1.0


P.S. If someone asked Nigel Garvey very politely, he could probably
come up with a much nicer and robust number parsing routine. :)


{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m
}
_______________________________________________
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.

  • Follow-Ups:
    • Re: "+" and "-" are numbers.
      • From: Emmanuel <email@hidden>
    • Re: "+" and "-" are numbers.
      • From: Paul Skinner <email@hidden>
  • Prev by Date: what's a "froplet"?
  • Next by Date: Re: Jaguar rebate
  • Previous by thread: Re: "+" and "-" are numbers.
  • Next by thread: Re: "+" and "-" are numbers.
  • Index(es):
    • Date
    • Thread