user72644: I would like to pass a formatted string to a method that accepts a __FlashStringHelper. Here is the method signature:
void myMethod(const __FlashStringHelper *str);

I have been using snprintf to format my string:
char cmd[30];
snprintf(cmd, 30, "There are %d seconds in a minute", 60);
myMethod(F(&cmd[0]));

Clearly the above doesn't work but how can I format a Flash String?
EDIT: I need to include an integer variable in my flash string. In the example above, '60' is a variable.
uint8_t nSeconds = 60;
char cmd[30];
snprintf(cmd, 30, "There are %d seconds in a minute", nSeconds);
myMethod(F(&cmd[0]));


user70020: Direct answer
F() takes immutable string literals, that are known at compile time, and places them into flash ("PROGMEM") instead of RAM.  snprintf() creates strings at runtime and places them into a mutable array.  The two things are fundamentally incompatible.
Limited compile-time concatenation
A very limited form of what you're trying to do could probably done like this:
#define MY_STRINGIZE(x) #x

myMethod(F("There are " MY_STRINGIZE(60) " seconds in a minute"));

This expands to:
myMethod(F("There are " "60" " seconds in a minute"));

Adjacent string literals are concatenated together, which makes this:
myMethod(F("There are 60 seconds in a minute"));

All that said, you could just write 60 in there directly.  And there's none of snprintf's formatting capabilities possible here.
There is not a compile-time version of snprintf available in Arduino.  And I don't think the features of the C++ (or C) language are there to support the creation of one either.  Odds are there is a better way of achieving what you really want to do.
Working around this altogether
Often it's not necessary to concatenate strings at all, particularly if you're just to turn around and write them to a Stream, or more generally Print subclass, e.g. Serial, LCD, SDFile, SoftwareSerial, etc.  Concatenating things for you is a large part of what these do.  It is not necessarily to do it yourself in advance.
If you have a string literal and constant (or variable) and want to keep as much of it out of RAM as possible, using two separate .print()/.println() helps you do this:
printCapableThing.print(F("AT+CIPSTAT="));
printCapableThing.println(index);


F() places "AT+CIPSTAT=" into flash.
If index is a constant it will also wind not being resident in RAM.

Side note
I realize you're asking about, getting as much into flash as possible, but I also can't help but point out this same basic technique applies to this otherwise awful idea, for somewhat different reasons:
Serial.println(String(F("Key ")) + keyname + " : " + value);

This creates a horrific mess of allocations and deallocations and unnecessary copying, where if you just let the Stream/Print object do its job by calling print()/println() multiple times.  The result code is more reliable, smaller, and where not I/O-bound, faster when you do.

72644: <p>I would like to pass a formatted string to a method that accepts a __FlashStringHelper. Here is the method signature:</p>
<pre><code>void myMethod(const __FlashStringHelper *str);
</code></pre>
<p>I have been using snprintf to format my string:</p>
<pre><code>char cmd[30];
snprintf(cmd, 30, &quot;There are %d seconds in a minute&quot;, 60);
myMethod(F(&amp;cmd[0]));
</code></pre>
<p>Clearly the above doesn't work but how can I format a Flash String?</p>
<p>EDIT: I need to include an integer variable in my flash string. In the example above, '60' is a variable.</p>
<pre><code>uint8_t nSeconds = 60;
char cmd[30];
snprintf(cmd, 30, &quot;There are %d seconds in a minute&quot;, nSeconds);
myMethod(F(&amp;cmd[0]));
</code></pre>
 70020: <h2>Direct answer</h2>
<p><code>F()</code> takes <em>immutable</em> string literals, that are known at <em>compile</em> time, and places them into flash (&quot;PROGMEM&quot;) instead of RAM.  <code>snprintf()</code> creates strings at <em>runtime</em> and places them into a <em>mutable</em> array.  The two things are fundamentally incompatible.</p>
<h2>Limited compile-time concatenation</h2>
<p>A <em>very limited</em> form of what you're trying to do could probably done like this:</p>
<pre class="lang-cpp prettyprint-override"><code>#define MY_STRINGIZE(x) #x

myMethod(F(&quot;There are &quot; MY_STRINGIZE(60) &quot; seconds in a minute&quot;));
</code></pre>
<p>This expands to:</p>
<pre class="lang-cpp prettyprint-override"><code>myMethod(F(&quot;There are &quot; &quot;60&quot; &quot; seconds in a minute&quot;));
</code></pre>
<p>Adjacent string literals are concatenated together, which makes this:</p>
<pre class="lang-cpp prettyprint-override"><code>myMethod(F(&quot;There are 60 seconds in a minute&quot;));
</code></pre>
<p>All that said, you could just write 60 in there directly.  And there's none of <code>snprintf</code>'s formatting capabilities possible here.</p>
<p>There is not a compile-time version of <code>snprintf</code> available in Arduino.  And I don't think the features of the C++ (or C) language are there to support the creation of one either.  Odds are there is a better way of achieving what you really want to do.</p>
<h2>Working around this altogether</h2>
<p>Often it's not necessary to concatenate strings at all, particularly if you're just to turn around and write them to a <code>Stream</code>, or more generally <code>Print</code> subclass, e.g. <code>Serial</code>, <code>LCD</code>, <code>SDFile</code>, <code>SoftwareSerial</code>, etc.  Concatenating things for you is a large part of what these do.  It is not necessarily to do it yourself in advance.</p>
<p>If you have a string literal and constant (or variable) and want to keep as much of it out of RAM as possible, using two separate <code>.print()</code>/<code>.println()</code> helps you do this:</p>
<pre class="lang-cpp prettyprint-override"><code>printCapableThing.print(F(&quot;AT+CIPSTAT=&quot;));
printCapableThing.println(index);
</code></pre>
<ul>
<li><code>F()</code> places <code>&quot;AT+CIPSTAT=&quot;</code> into flash.</li>
<li>If index is a constant it will also wind not being resident in RAM.</li>
</ul>
<h2>Side note</h2>
<p>I realize you're asking about, getting as much into flash as possible, but I also can't help but point out this same basic technique applies to this otherwise awful idea, for somewhat different reasons:</p>
<pre class="lang-cpp prettyprint-override"><code>Serial.println(String(F(&quot;Key &quot;)) + keyname + &quot; : &quot; + value);
</code></pre>
<p>This creates a horrific mess of allocations and deallocations and unnecessary copying, where if you just let the Stream/Print object do its job by calling <code>print()</code>/<code>println()</code> multiple times.  The result code is more reliable, smaller, and where not I/O-bound, faster when you do.</p>
