Re: Sequential Numbering
Re: Sequential Numbering
- Subject: Re: Sequential Numbering
- From: Justin Middleton <email@hidden>
- Date: Fri, 16 Sep 2005 12:23:30 -0700
I'm sure there's a better way to do this, but the following will work:
-- replace the rightmost characters of the string
-- representation of inPadding with the string
-- representation of inValue, truncating inValue if
-- necessary.
on rPadInto(inPadding, inValue)
set theStr to ((inPadding as string) & (inValue as string))
return (characters ((length of theStr) - ((length of inPadding)
- 1)) thru (length of theStr) of theStr) as string
end rPadInto
Use it thusly:
rPadInto("0000", 120)
>>> "0120"
The string your inserting into can be any string, and doesn't have to
be longer than the value you're inserting... if it's not, the value
will be truncated on the left.
rPadInto("---", 3225)
>>> "225"
To generate the output you want, do something like this:
-- example usage
set nums to {}
repeat with i from 1 to 1000
set end of nums to (rPadInto("0000", i))
end repeat
nums
>>> (* a list of 4-digit numbers from 0001 through 1000)
For the sake of brevity, I'm omitting the output... but you get the
idea.
Now, can someone show me an easy way to multiply strings in
AppleScript, ala python's overloaded multiplication operator, or
perl's "string" x numTimes?
/j
On Sep 16, 2005, at 11:36 AM, email@hidden wrote:
Would some one please forward a repeat loop to do the following:
Make numbers starting with:
0001
and ending with"
1000
I tried for hours to locate with out success.
Thanks
--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (Applescript-
email@hidden)
Help/Unsubscribe/Update your Subscription:
40mac.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden