String handling

How can i reformat this:

{“WED 01DEC10 15:00”}

to a useable date format like:

“WED 01 Dec 10 15:00”

I suggest that you use Ruby’s or Perl’s regular expression facilities. For example:


-- Replaces all matches of regular expression regex with newString in theText
-- If |caseSensitive?| is true then the matching is case sensitive, otherwise it is case insensitive
-- Regular expression syntax is Ruby's syntax
on replaceRegExp(regex, newString, theText, |caseSensitive?|)
	if |caseSensitive?| then
		set ci to "i"
	else
		set ci to ""
	end if
	set theRubyOneLiner to quote & "s = '" & theText & "'; s.gsub!(/" & regex & "/" & ci & ",'" & newString & "'); puts s" & quote
	set theCommand to "ruby -e " & theRubyOneLiner
	do shell script theCommand
end replaceRegExp

-- Example of usage:
set s to item 1 of {"WED 01DEC10 15:00"}
replaceRegExp("(\\d\\d)(\\w{3})(\\d\\d)", "\\1 \\2 \\3", s, false)

The first argument of replaceRegExp() is a Perl-like regular expression. Using that syntax, \d denotes a single digit, \w denotes a single alphanumerical character, {n} specifies that the preceding pattern must be repeated n times, and parentheses are used to group subexpressions. Such groups can be referred to in the replacement string (the second argument of replaceRegExp()) by \1, \2, \3 and so on. Note that AppleScript requires that the backslash be escaped in strings (that is, you need to write \ instead of ).

Hope this helps.

Thank you very much.

That is perfect.