Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'better leading zeros code' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
better leading zeros code
Authored by: airdrummer on Jan 09, '07 04:17:13AM
eliminate the tedious if then(/else;-)s:

          set prefixName to (text -4 thru -1 of ("0000" & i)) & " - "


[ Reply to This | # ]
better leading zeros code
Authored by: peterrosen on Jan 11, '07 04:24:01AM

Please don't assume we all know where to put the code you suggest! Could you specifiy what it replaces? Also the author mentions potential adjustments. What is he meaning?



[ Reply to This | # ]
sorry, i assumed u would RTFC;-)
Authored by: airdrummer on Jan 11, '07 05:40:22AM
replace this:
		set prefixName to ""
		if i < 1000 then
			set prefixName to "0" & prefixName
		end if
		if i < 100 then
			set prefixName to "0" & prefixName
		end if
		if i < 10 then
			set prefixName to "0" & prefixName
		end if
		set prefixName to prefixName & i & " - "
with my 1 liner...

i would also replace

		set alreadyNumbered to true
		repeat with j from 1 to 4
			if character j of oldPhotoName is not in {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} then
				set alreadyNumbered to false
			end if
		end repeat
		if (" - " is not (characters 5 thru 7 of oldPhotoName as string)) and not alreadyNumbered then
			set the name of item i of thePhotos to prefixName & oldPhotoName
			set renamedNumber to renamedNumber + 1
		end if
with
               try      -- resort to cli cuz a/s sux 4 pattern matching;-}
                    do shell script " echo "& quoted form of (oldPhotoName as string) & " | egrep '^[0-9]* - '"
			set the name of item i of thePhotos to prefixName & oldPhotoName
			set renamedNumber to renamedNumber + 1
		on error
                        -- dss throws exception when not found
                end try


[ Reply to This | # ]