Breaking apart a string based on # of characters?

I have some strings like these…

05-30-2008 MD Slider.mov
05-29-2008 MD Slider.mov
05-28-2008 MD Slider.mov

I have two things I want to do: Isolate the date into one variable and the rest of the string (minus “.mov”) into another.

I know the first 10 characters will always be the date, but the multiple spaces are messing with my ability to get the rest out via AppleScript Text Item Delimiters. I figured I could use a space as the delimiter then get the date


	set AppleScript's text item delimiters to space
	set theDate to text item 1 of this_item

…and this worked. Then I thought I’d use “.mov” as the next delimiter to isolate the “MD Slider” text, but instead I got “05-30-2008 MD Slider”. Obviously, I realized, since the first text item delimiter operation didn’t remove the date characters from the this_item variable.

This got me thinking I cannot rely on spaces as delimiters.

I can count on the first 10 characters being my date, so can I remove the first 10 characters into my Date variable leaving the " MD Slider.mov" in the either the original variable or in a new one? This non-date string can easily lose its “.mov” and the leading space to get the second part of what I need.

Hi,

try this


set theString to "05-30-2008 MD Slider.mov"

set {TID, text item delimiters} to {text item delimiters, space}
tell theString to set {theDate, theName} to {text item 1, text items 2 thru -1 as text}
set text item delimiters to TID
set theName to text 1 thru ((offset of ".mov" in theName) - 1) of theName

Hi.

If the format’s definitely 10 characters of date, then a space, then a name of unknown length, then the four characters “.mov”, you don’t need to use delimiters:

set theString to "05-30-2008 MD Slider.mov"

set theDate to text 1 thru 10 of theString
set theName to text 12 thru -5 of theString

The -5 part, does that mean “the end” since we don’t know how many characters long the name could be?

EDIT: Oh, it means “5 from the end” doesn’t it? That’s awesome. Thanks!