question about find and replace

Brian Yennie briany at qldlearning.com
Tue Sep 30 15:31:44 EDT 2008


Just for diversity's sake, I have often used a function like the  
following:

function zeroPad pText,pLength
  repeat max(0, pLength - length(pText))
     put "0" before pText
  end repeat
  return pText
end zeroPad

put zeroPad("13", 4) => "0013"
put zeroPad("5", 4) => "0004"

etc.

> Recently, Peter Alcibiades wrote:
>
>> How do you pad out a series of numbers with leading zeros?  Like  
>> for instance
>> the series is
>>
>> .1.
>> .2.
>> .3.
>> .11.
>> .42.
>> .98.
>>
>> and you want them to be
>>
>> .001.
>> .002.
>> .003.
>> .011.
>> .042.
>> .098.
>
> You can use the format function.  For example:
>
> answer format("%03s",1)
>
> will display 001 (the 3 means pad with zeros to 3 places).  So if the
> decimal points in your number series are intentional, you could make a
> function like:
>
> function padNumbers pSeries
>   repeat for each line tNum in pSeries
>     put "." & format("%03s",char 2 to -2 of tNum) & "." & cr after  
> newSet
>   end repeat
>  return newSet
> end padNumbers
>
>
> Regards,
>
> Scott Rossi
> Creative Director
> Tactile Media, Multimedia & Design






More information about the use-livecode mailing list