Comparing two numbers

This seems easy, but I haven’t been able to find it by searching the forum, so I’m sorry if this is something incredibly obvious… I’m working on an app where I need to compare two numbers. It’s nothing fancy, all the app needs to know is whether the two numbers are different or the same.

Basically, if they were different, variable 1 would be in the format of “#1,423,520 in blah” and variable 2 would be in the format of “#2,304 in blah”. The app would need to know whether the numbers between “#” and " in blah" are the same in both variables, or different.

Thanks in advance, and, again, sorry if this is a stupid question. :slight_smile:

Hi,

If in blah is the same in both strings and the numbers are integers, then just compare the strings:

set t1 to “#1,423,520 in blah”
set t2 to “#2,304 in blah”
t1 = t2
→ false

gl,

Wow, I think I just set a new record for stupid AppleScript questions. Thanks for the fast reply! :smiley:

Hi Mr. Me,

No question is stupid.

You might be thinking about how you can coerce the textual representation of a number with commas to a number. You can just remove the commas, then coerce to number or integer. e.g.

set x to “1,200,000”
set d_tid to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to “,”
set temp_list to text items of x
set AppleScript’s text item delimiters to d_tid
set nx to (temp_list as string) as integer

This replaces the commas with empty string (“”).

gl,