Re: Adding a leading zero
Re: Adding a leading zero
- Subject: Re: Adding a leading zero
- From: Michelle Steiner <email@hidden>
- Date: Wed, 4 Apr 2007 14:19:35 -0700
On Apr 4, 2007, at 1:36 PM, <email@hidden>
<email@hidden> wrote:
thanks for your answer. What I had in mind was piping it thru sed
or something like that. The leading zero is only needed for dates
0-9. The month will always be three chacters and the year four
digits, it is only the day that will vary
I have been playing with InDesign JavaScript and come up with a two
step solution.
myString='Apr42007'
myString=myString.replace(/(\D+)(\d+)/, '$10$2');
myString=myString.replace(/(\D{3})(\d{6}$)/, '$1$2');
I am sure this can be done much more simple and elegant, but I
don't know how to transfer it to a tool like sed.
All I know is Applescript, so I gave a vanilla Applescript solution.
The string will always be either eight or nine characters, depending
on the number of characters in the day. If there are eight
characters, that means that the date is 1 through 9, so a zero needs
to be inserted after the third character. That's what my suggestion
does. Unfortunately, Applescript does not have an insert function,
but one can be written:
insert of "0" from 3 into "Apr42007"
on insert of inserted_text from position into original_text
return text 1 through position of original_text & inserted_text &
text (position + 1) through end of original_text
end insert
-- Michelle
--
"As a matter of general principle, I believe there can be no doubt
that criticism in time of war is essential to the maintenance of any
kind of democratic government ... too many people desire to suppress
criticism simply because they think that it will give some comfort to
the enemy to know that there is such criticism." -- Robert A. Taft,
December 19, 1941
_______________________________________________
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