5
$\begingroup$

Is there a way to Print a message suitable for Message? I want to recycle some messages (but Print them, so they don't get suppressed after X times and look like Print output).

E.g.

Test::message="This is test number `1`."; Message[Test::message,1] 

enter image description here

Desired functionality:

PrintMessage[Test::message,1] (* This is test number 1. *) 

The inserting parts between back ticks is what really had me confused.

$\endgroup$

1 Answer 1

5
$\begingroup$

Just use StringForm:

PrintMessage[mess_, val__] := Print@StringForm[mess, val] 

Or StringTemplate:

PrintMessage[mess_, val__] := Print@StringTemplate[mess][val] 
$\endgroup$
1
  • $\begingroup$ Thanks, I was digging around in the docs but didn't stumble on either of these. $\endgroup$ Commented Oct 19, 2020 at 2:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.