Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wouldn't use <code>PaddedForm</code> for this. In fact, I'm not sure that <code>PaddedForm</code> is good for much of anything. Instead, I'd use good old <code>ToString</code>, <code>Characters</code> and <code>PadLeft</code>, like so:</p> <pre><code>toFixedWidth[n_Integer, width_Integer] := StringJoin[PadLeft[Characters[ToString[n]], width, "0"]] </code></pre> <p>Then you can use <code>StringForm</code> and <code>ToString</code> to make your file name:</p> <pre><code>toNumberedFileName[n_Integer] := ToString@StringForm["filename_``", toFixedWidth[n, 5]] </code></pre> <p>Mathematica is not well-suited to this kind of string munging. </p> <p><strong>EDIT to add:</strong> Mathematica proper doesn't have the required functionality, but the <code>java.lang.String</code> class has the static method <code>format()</code> which takes <code>printf</code>-style arguments. You can call out to it using Mathematica's JLink functionality pretty easily. The performance won't be very good, but for many use cases you just won't care that much:</p> <pre><code>Needs["JLink`"]; LoadJavaClass["java.lang.String"]; LoadJavaClass["java.util.Locale"]; sprintf[fmt_, args___] := String`format[Locale`ENGLISH,fmt, MakeJavaObject /@ Replace[{args}, {x_?NumericQ :&gt; N@x, x : (_Real | _Integer | True | False | _String | _?JavaObjectQ) :&gt; x, x_ :&gt; MakeJavaExpr[x]}, {1}]] </code></pre> <p>You need to do a little more work, because JLink is a bit dumb about Java functions with a variable number of arguments. The <code>format()</code> method takes a format string and an array of Java <code>Object</code>s, and Mathematica won't do the conversion automatically, which is what the <code>MakeJavaObject</code> is there for.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload