4
$\begingroup$

When I type

a <> "0" /. {a -> "1"}

I get the error

StringJoin::string: String expected at position 1 in a<>0. >>

Followed by the answer I want

"10"

What should I do instead so that I don't get the error?

$\endgroup$

2 Answers 2

4
$\begingroup$

Use one of the following

a <> "0" /. {a -> "1"} // Quiet

or

ReleaseHold[Hold[a <> "0"] /. {a -> "1"}]
$\endgroup$
3
$\begingroup$

Make a lazier StringJoin:

stritch[a_String, b_String] := a <> b
stritch[a, "0"] /. a -> "1"
(* 10 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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