Hi Mohammad, Your macros show a deep knowledge of the tools in TW.
I'm a bit concerned that each level of indenture requires another chunk of code, which may be hard to maintain. The thing is, this sort of thing is easy if you have the right text tools. We need the concat function and a substr function. Unfortunately the new tools lack the substr. How do you feel about using javascript macros (and filters) in TW-commander? I just thought of another approach. Maybe. You could use a list filter and call it recursively. Each time you prefix a "0". When the length (new math function?) reaches the padded number length, the recursion ends and the result is sent back. The problem here is that I don't the parameters for the length function. The length would have to be compared to the target length and the only comparison tool is the revealwidget. -- Mark On Friday, February 15, 2019 at 8:31:53 AM UTC-8, Mohammad wrote: > > Mark, > String operation are added to TW - prerelease, see below > > Ref: > > - > > https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/filters/strings.js > - > > https://github.com/Jermolene/TiddlyWiki5/commit/9b2d52716a24197ba9fd67b708cbe2c56fa1b5d0 > > > By the way, please let me know your opinion on the above macros. > > --Mohammad > > On Friday, February 15, 2019 at 7:57:17 PM UTC+3:30, Mark S. wrote: >> >> Like others in the forum, I'm finding that search links do not work. You >> had a post earlier (which I can't get to) about new string operators being >> added in the pre-release. But there's no documentation for string operators >> -- only the new math operators. >> >> I'm wondering if, with the new string operators, it would be possible to >> make a simpler, more concise padding macro that could provide any level of >> padding? >> >> Could you share any information or documentation you've uncovered about >> the string operators? >> >> Thanks! >> -- Mark >> >> On Friday, February 15, 2019 at 8:18:05 AM UTC-8, Mohammad wrote: >>> >>> Asked by Josiah here: >>> >>> https://groups.google.com/d/msg/tiddlywiki/w9Bv-WulKw8/O3RaMUwqBAAJ >>> >>> To produce numbers zero padded like >>> >>> 001 >>> 002 >>> 003 >>> ... >>> >>> 099 >>> 100 >>> >>> Here is a macro to do that >>> >>> \define zeropad-range(n:10) >>> <$list filter="[range[1,$n$]]" variable=x > >>> <$reveal type="lteq" default=<<x>> text="9" > >>> <$text text= {{{[<x>addprefix[00]]}}} /> >>> </$reveal> >>> <$reveal type="gt" default=<<x>> text="9" > >>> <$text text= {{{[<x>addprefix[0]]}}} /> >>> </$reveal> >>> </$list> >>> \end >>> >>> Example >>> >>> 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017018 >>> 019 020 021 022 023 024 025 >>> >>> The below macro works up to 1000 >>> >>> \define zeropad-range4(n:10) >>> <$list filter="[range[1,$n$]]" variable=x > >>> <$reveal type="lteq" default=<<x>> text="9" > >>> <$text text= {{{[<x>addprefix[000]]}}} /> >>> </$reveal> >>> <$reveal type="gt" default=<<x>> text="9" > >>> <$reveal type="lt" default=<<x>> text="99" > >>> <$text text= {{{[<x>addprefix[00]]}}} /> >>> </$reveal> >>> </$reveal> >>> <$reveal type="gt" default=<<x>> text="99" > >>> <$text text= {{{[<x>addprefix[0]]}}} /> >>> </$reveal> >>> </$list> >>> \end >>> >>> >>> >>> --Mohammad >>> >> -- 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/0d4d7a01-fb9e-49c3-812f-38ba9617e4bd%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

