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$
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$
    – Chris K
    Oct 19 '20 at 2:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.