When does one need StringJoin as opposed to StringExpression? I don't know of an example where s1<>s2<>...<>sn works but s1~~s2~~...~~sn does not.

  • 3
    $\begingroup$ From here "StringExpression is closely related to StringJoin, except nonstrings are allowed and lists are not flattened. For pure strings, they are equivalent." $\endgroup$
    – Jason B.
    Nov 25, 2015 at 12:31
  • 3
    $\begingroup$ Generally, you should consider StringJoin as on operation for joining strings together, while StringExpression is meant for pattern matching strings when using functions like StringCases, StringMatchQ and StringPosition. A StringExpression is much more like a regular expression in that sense. $\endgroup$ May 8, 2017 at 13:14

1 Answer 1


Based on @Jason B's comment, StringJoin can handle (and flattens) lists.

StringJoin[{"Ab", "cd"}, {"ef"}] returns Abcdef, whereas StringExpression[{"Ab", "cd"}, {"ef"}] returns {"Ab", "cd"} ~~ {"ef"}.

  • 1
    $\begingroup$ But it works too, StringCases[ "bf", {"b", "d"} ~~ {"f"}], so what works better? :) $\endgroup$
    – Kuba
    Nov 25, 2015 at 13:05

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.