• 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: Easier way to check for numbered string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Easier way to check for numbered string


  • Subject: Re: Easier way to check for numbered string
  • From: "Stockly, Ed" <email@hidden>
  • Date: Fri, 27 Apr 2007 12:39:10 -0700
  • Thread-topic: Easier way to check for numbered string

Title: Re: Easier way to check for numbered string

>    I have a script that goes through and pulls specific characters  
> out of a filename and checks to see if they are all numbers.  While  
> it works now, I was hoping somebody knew of a more efficient way of  
> doing this.  

This may not be the most efficient way of doing it, but it works for me.

You can adjust the values of the variable positionsToTest to pick any characters in your file name.

The result is a list of the file names that failed.

HTH,

ES
---------------------

set fileNames to {"No Numbers", "1234567890", "12andletters", "lettersand12"}
set allNumbers to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
set text item delimiters to ""
set failedTest to {}
repeat with thisName in fileNames
    set nameStringlist to every text item of thisName
    set positionsToTest to {-1, -2} --last 2 numbers
    --set positionsToTest to {1, 2} -- first 2 numbers
    --set positionsToTest to {1, 2, 4, -1, -2} --arbitrarily selected numbers
    repeat with thisNumber in positionsToTest
        if the (count of nameStringlist) ≥ thisNumber then
            if item thisNumber of nameStringlist is not in allNumbers then
                set the end of failedTest to thisName as string
                exit repeat
            end if
        end if
    end repeat
end repeat
return failedTest
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: Easier way to check for numbered string
  • Next by Date: Re: perl regex works differently within a "do shell script" than from within perl
  • Previous by thread: Re: Easier way to check for numbered string
  • Next by thread: Excel problems switching between documents
  • Index(es):
    • Date
    • Thread