Tag Info

Hot answers tagged


It is my impression (based solely on the examples in the documentation) that in the context of strings Except only allows single-letter strings. Compare StringMatchQ["q", Except["p"]] True with StringMatchQ["qq", Except["pp"]] Therefore, you generally need to rephrase your string patterns using the StringPattern and RegularExpression syntax. ...


This syntax coloring bug [264325] was fixed in Mathematica 10.0.2:


Since we can not see the source code of Mathematica, we don't know the detailed algorithm Mathematica use to do string pattern searching. But in most other languages, they use KMP algorithm to do explicit string matching. KMP is in fact a very compact design of the DFA pattern matching algorithm. You can find a comparison here. You can see that the ...


You can use the high-level functions to build your string expression for this: StringCases[a1, "struct " ~~ name__ ~~ "{" :> name] (* {{"name1 "}, {"name2"}, {"name3"}, {"name4"}, {"name5"}, {"lastStruct"}} *) If you really need a RegularExpression then there is nothing simpler than starting with the high-level functions and let Mathematica figure out ...


Let me give you at least a start, because in general, I like this question. There are some things that are still unclear. For instance, you write in the comment and has as child name 2 who has two childs name 3 and 4 . etc Regarding the example you gave, this is not correct. name2 has one child which is name3 which in return has one child name4. Look ...


Your data {a, b, c, d} = RandomInteger[9, 4]; data = a b c d; Exporting with nice file-names featuring date and variable values using StringTemplate Export[ StringTemplate[ "Date`1`_Values_a`2`_b`3`_c`4`.txt" ][DateString[{"Year", "Month", "Day"}], a, b, c] , data] "Date20141201_Values_a7_b5_c3.txt" Or using ToString and StringJoin as ...


The other commentators are correct that Except does only allows single-letter strings. Note that you could also use RegularExpression here: StringReplace["xxxyxz", RegularExpression["x[^y]"] -> "ww"]


Better late the never, right? I created this answer while thinking about one of recent questions that was a duplicate of this one. I kind of like this way, it is compact and without #&@ :) ClearAll[VNL]; SetAttributes[VNL, HoldFirst]; VNL[list_] := Thread[ Hold[list] /. OwnValues[list] ] /. Hold[s_] ...


Using Regular expressions, as requested: StringCases[a1, RegularExpression["struct (.*)[ ]*\{"] :> "$1"] (* {{"name1 "}, {"name2"}, {"name3"}, {"name4"}, {"name5"}, {"lastStruct"}} *)


This has been fixed in Version 10.0.2. On windows: TextString[-0.5]


Using insights from WReach and Aisamu here's a version with good properties on system names: humpCharacters = Flatten@{CharacterRange["A", "Z"], CharacterRange["0", "9"]}; . StringSplit[systemNames, c : humpCharacters ~~ rest : Except[Append[humpCharacters, "$"]] .. :> c <> rest] // // Map[Select[# != "" &]] From visual ...


pF = Pick[#, StringMatchQ[#, "*and*", IgnoreCase -> True]] & pF@{"xyzw", "andxxxx", "abANDcc"} (* {"andxxxx", "abANDcc"} *)


Maybe something like this? myfun[j_] := Block[{ans = Range[j]}, ToExpression["phi" <> ToString[j] <> " = " <> ToString@Total[ans]] ]; myfun[10]; phi10 55


I believe this accomplishes your goal: Table[ContourPlot[ Norm[{x, y}, p] == 1, {x, -1.2, 1.2}, {y, -1.2, 1.2}, PerformanceGoal -> "Accuracy", ImageSize -> 250, PlotLabel -> Row[{TraditionalForm[HoldForm[p]], "\[ThinSpace]=", p}]], {p, {1, 2, 3, 4, 10, 50, 500}}] The \[ThinSpace] is included just to properly space before the equal ...

Only top voted, non community-wiki answers of a minimum length are eligible