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.

  • 2
    $\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 '15 at 12:31
  • 2
    $\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 '17 at 13:14

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"}.

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

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.