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.
1 Answer
$\begingroup$
$\endgroup$
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$– KubaCommented Nov 25, 2015 at 13:05
StringJoin
as on operation for joining strings together, whileStringExpression
is meant for pattern matching strings when using functions likeStringCases
,StringMatchQ
andStringPosition
. AStringExpression
is much more like a regular expression in that sense. $\endgroup$