A little late to the party. Here's my version, that takes any number (or 
character) for padding:

\define padder-reg() ^$(len)$$
\define padder(str,len,chr:"0")
<$vars len=<<__len__>>>
<$list filter="[<__str__>addprefix<__chr__>]" variable="padstr">
<$list filter="[<padstr>length[]!regexp<padder-reg>]" emptyMessage=<<padstr
>>>
<$macrocall $name="padder" str=<<padstr>> len=<<__len__>> chr=<<__chr__>>/>
</$list>
</$list>
</$vars>
\end

<<padder "25" "15">>

The weakness is if the starting number has more characters than the pad 
number, it will never complete.

-- Mark

On Friday, February 15, 2019 at 11:28:24 AM UTC-8, Mohammad wrote:
>
> Added to TW-Scripts.
>
> On Friday, February 15, 2019 at 10:31:43 PM UTC+3:30, Eric Shulman wrote:
>>
>> On Friday, February 15, 2019 at 9:36:26 AM UTC-8, Mohammad wrote:
>>>
>>>  But we do not know in advance what is the number, and it is given by 
>>> user!
>>> So if n is a variable, then how we can generate these numbers?
>>>
>>>>
>> If we DID know the number in advance, we could just use it in the operand 
>> of the range[...]
>>
>> For example, suppose the desired number is, say, 256.  Then we could just 
>> modify the filter be:
>> [range[9]addprefix[00]] [range[10,99]addprefix[0]] [range[100,256]]
>>
>> However, since you want the number to be "given by user", we need to use 
>> a different approach.  Instead of hard-coding the number, we can use the 
>> limit[...] filter.  Let's suppose the desired number is in variable called 
>> "max".  Then we could write:
>> [range[9]addprefix[00]] [range[10,99]addprefix[0]] [range[100,999] +[
>> limit<max>] 
>>
>> and if the desired number is in a tiddler (e.g. $:/temp/input/userlimit, 
>> as a result of user input), we could write:
>> [range[9]addprefix[00]] [range[10,99]addprefix[0]] [range[100,999] +[
>> limit{$:/temp/input/userlimit}]
>>
>> -e
>>
>> note: edited to fix missing syntax in last two examples.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/81c8479d-153b-42cc-b924-74aa6b9ff019%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to