# Printf with variable format string

**URL:** <https://discourse.julialang.org/t/printf-with-variable-format-string/3805>\
**Category:** General Usage\
**Tags:** strings, formatting, printf\
**Created:** [May 19, 2017, 10:53am UTC](https://discourse.julialang.org/t/printf-with-variable-format-string/3805 "2017-05-19T10:53:39Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)\
**Post date:** [May 22, 2023, 5:14pm UTC](https://discourse.julialang.org/t/printf-with-variable-format-string/3805/10 "2023-05-22T17:14:08Z")

</div>

thanks so much @Paul_Soderlind !

since `format` is not exported, and so isn’t [documented](https://docs.julialang.org/en/v1/stdlib/Printf/), here’s specifically what i got to work:

```julia
julia> using Printf

julia> w=9
9

julia> fmt = Printf.Format("%$(w)d")
Printf.Format{Base.CodeUnits{UInt8, String}, Tuple{Printf.Spec{Val{'d'}}}}(UInt8[0x25, 0x39, 0x64], UnitRange{Int64}[1:0, 4:3], (%9.0d,))

julia> Printf.format(stdout, fmt,16)
       16

```

---

_[View the full topic](https://discourse.julialang.org/t/printf-with-variable-format-string/3805)._
