Tag Info

Hot answers tagged

9

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


6

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


5

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


4

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


3

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


3

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


3

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"]


2

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_] ...


1

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


1

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


1

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


1

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


1

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


1

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