• 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: String manipulation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String manipulation


  • Subject: Re: String manipulation
  • From: Luther Fuller <email@hidden>
  • Date: Thu, 06 Jun 2013 17:38:50 -0500

On Jun 6, 2013, at 4:36 PM, Iurista GmbH wrote:

I have Filenames in form of "some_text xx.xx.xx some_text", where xx.xx.xx is a date (german syntax: ie. 01.06.13 for the first of June)
I try to convert the "date part"  into the form YYMMdd (ie. 130601).

The tricky thing is to get the part "xx.xx.xx", which I highlight in Finder, to be copied.

I would get rid of the GUI scripting, if that's possible.
Here is what I quickly tried …

property filename : "some_text 1.6.13 some_text"

set AppleScript's text item delimiters to {space}
set dateWord to 0
set fileNameWords to (text items of filename) as list
repeat with i from 1 to (count items of fileNameWords)
if item i of fileNameWords contains "." then
set oldDate to (item i of fileNameWords) as text
set dateWord to i
exit repeat
end if
end repeat

if dateWord = 0 then return -- error dialog needed here

set AppleScript's text item delimiters to {"."}
set newDay to text item 1 of oldDate
set newMonth to text item 2 of oldDate
set newYear to text item 3 of oldDate

if length of newDay < 2 then set newDay to ("0" & newDay)
if length of newMonth < 2 then set newMonth to ("0" & newMonth)

set newDate to (newYear & newMonth & newDay)

set item dateWord of fileNameWords to newDate
set AppleScript's text item delimiters to {space}
set newFileName to fileNameWords as text

display dialog filename & return & return & newFileName

It works, but I am not aware of details of your situation which may pose a problem.

You can select the file (not just part of the file name) and let your script find the date part.
But ...
Is the date part of your file always delimited by spaces?
If not, then the script above will not be able to identify the date part.
And, do your file names have an extension?
If they do, you will first have to get the file name without the extension.

Hope this helps, however.




 _______________________________________________
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

References: 
 >String manipulation (From: Iurista GmbH <email@hidden>)

  • Prev by Date: String manipulation
  • Next by Date: Re: String manipulation
  • Previous by thread: String manipulation
  • Next by thread: Re: String manipulation
  • Index(es):
    • Date
    • Thread