Re: [julia-users] @sprintf variable length padding
Not currently supported via printf. On Wed, Jul 20, 2016 at 10:32 AM, Tamas Papp wrote: > Thanks --- this is helpful for my particular problem, but I am still > curious about how to do this with @sprintf (or whether it is currently > not supported). > > Best, > > Tamas > > On Wed, Jul 20 2016, Stefan Karpinski wrote: > > > julia> lpad(12, 4, 0) > > "0012" > > > > On Wed, Jul 20, 2016 at 9:05 AM, Tamas Papp wrote: > > > >> Hi, > >> > >> how can I @sprintf an integer i padded to length l with zeros, where l > >> is not a constant? Current workaround is > >> > >> printpad(i, l) = mapreduce(string, *, reverse(digits(i, 10, l))) > >> > >> julia> printpad(12, 4) > >> "0012" > >> > >> but I could not figure out how to do this with @sprintf. If my > >> understanding of printf syntax is correct, something like > >> > >> @sprintf("%*d", 4, 12) > >> > >> should do the trick, but in Julia it is an invalid format string. > >> > >> Best, > >> > >> Tamas > >> > >
Re: [julia-users] @sprintf variable length padding
Thanks --- this is helpful for my particular problem, but I am still curious about how to do this with @sprintf (or whether it is currently not supported). Best, Tamas On Wed, Jul 20 2016, Stefan Karpinski wrote: > julia> lpad(12, 4, 0) > "0012" > > On Wed, Jul 20, 2016 at 9:05 AM, Tamas Papp wrote: > >> Hi, >> >> how can I @sprintf an integer i padded to length l with zeros, where l >> is not a constant? Current workaround is >> >> printpad(i, l) = mapreduce(string, *, reverse(digits(i, 10, l))) >> >> julia> printpad(12, 4) >> "0012" >> >> but I could not figure out how to do this with @sprintf. If my >> understanding of printf syntax is correct, something like >> >> @sprintf("%*d", 4, 12) >> >> should do the trick, but in Julia it is an invalid format string. >> >> Best, >> >> Tamas >>
Re: [julia-users] @sprintf variable length padding
julia> lpad(12, 4, 0) "0012" On Wed, Jul 20, 2016 at 9:05 AM, Tamas Papp wrote: > Hi, > > how can I @sprintf an integer i padded to length l with zeros, where l > is not a constant? Current workaround is > > printpad(i, l) = mapreduce(string, *, reverse(digits(i, 10, l))) > > julia> printpad(12, 4) > "0012" > > but I could not figure out how to do this with @sprintf. If my > understanding of printf syntax is correct, something like > > @sprintf("%*d", 4, 12) > > should do the trick, but in Julia it is an invalid format string. > > Best, > > Tamas >
[julia-users] @sprintf variable length padding
Hi, how can I @sprintf an integer i padded to length l with zeros, where l is not a constant? Current workaround is printpad(i, l) = mapreduce(string, *, reverse(digits(i, 10, l))) julia> printpad(12, 4) "0012" but I could not figure out how to do this with @sprintf. If my understanding of printf syntax is correct, something like @sprintf("%*d", 4, 12) should do the trick, but in Julia it is an invalid format string. Best, Tamas