As Objective C identifies integers as decimal digit characters, it possible to extract integers from a string without using Objective C’s inversion method.
Although the following script successfully extracts digits from a ten digit phone number, I want to write the script in a more concise fashion.
use framework "Foundation"
use scripting additions
set SourceText to "(123)456-7890"
# Create an NS String from the SourceText.
set SourceNSString to (current application's NSString's stringWithString:SourceText)
# Get all characters which are not digits 0 through 9.
set nonDigitCharacterSet to (current application's NSCharacterSet's decimalDigitCharacterSet's invertedSet())
# Extract components of the SourceText that are not included in the prior inversion, ie, that are in the set of characters representing digits 0 through 9.
set ExtractedNumberListsOfStrings to SourceNSString's componentsSeparatedByCharactersInSet:nonDigitCharacterSet
# Join the list of component strings using "" as the text item delimiter.
ExtractedNumberListsOfStrings's componentsJoinedByString:""
# Yields 1234567890
What other Applescript Objective C alternatives might provide a more concise method?