Is it possible to take a number range such as 38-41 (numbers separated by a hyphen) and return a list such as 38, 39, 40, 41?
Thanks
Is it possible to take a number range such as 38-41 (numbers separated by a hyphen) and return a list such as 38, 39, 40, 41?
Thanks
Rob:
Try this:
set raw_Range to text returned of (display dialog "Enter a range of numbers (e.g. 45-55):" default answer "")
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "-"
set clean_Range to raw_Range's every text item
set AppleScript's text item delimiters to astid
set final_List to {}
repeat with x from (clean_Range's item 1) to (clean_Range's item 2)
set end of final_List to x
end repeat
final_List
It is simple, and assumes that the user knows what she/he is doing. It could (of course) be made much more complicated to check for errors and such…
Hope this helps,
Thanks Craig.
One more thing…
What if the list is “8, 38-41” and I need “8, 38, 39, 40, 41”
I’m sure there is an easier way to do this but my mind is not in
full gear this morning.
set the_string to "38-41"
--set the_string to "8, 12-15"
my getNumList(the_string)
on getNumList(the_string)
if the_string contains "," then
set the_delims to {",", "-"}
set {numAlone, startRange, endRange} to {item 1, item 2, item 3} of my multi_atid_split(the_string, the_delims)
set final_List to numAlone
repeat with x from startRange to endRange
set final_List to final_List & ", " & x
end repeat
else
set the_delims to {"-"}
set {startRange, endRange} to {item 1, item 2} of my multi_atid_split(the_string, the_delims)
set final_List to ""
repeat with x from startRange to endRange
set final_List to final_List & x & ", "
end repeat
set final_List to text 1 thru -3 of final_List
end if
end getNumList
on multi_atid_split(the_string, the_delims)
set {OLD_delim, temp_delim} to {AppleScript's text item delimiters, "?|?"}
repeat with this_delim in the_delims
my atid(this_delim)
set the_string to text items of the_string
my atid(temp_delim)
set the_string to text items of the_string as string
end repeat
my atid(temp_delim)
set the_string to text items of the_string
my atid(OLD_delim)
return the_string
end multi_atid_split
on atid(the_delim)
set AppleScript's text item delimiters to the_delim
end atid
Thanks Craig