Tag Info

Hot answers tagged

5

Use the Variables command: Variables[a x^2 + b x + c] (* {a,b,c,x} *) You can easily remove the x. Alternatively: CoefficientList[a x^2 + b x + c, x] (* {a, b, c} *)


3

For performance fiends: I had an application that had this very need for some huge sets of long integer strings. kguler's solution is certainly the canonical way, and quite quick, as is Felix's version (I was actually surprised on that one). eldo's solution is probably what most would come up with, but in performance-intensive scenarios the StringSplit is ...


3

A quite general approach is to use Cases. Cases[a^3 + b^2 + c, z_Symbol :> z, {0, Infinity}] (* {a, b, c} *) or Cases[Cos[a] b^c Gamma[d]/e, z_Symbol :> z, {0, Infinity}] (* {b, c, e, a, d} *)


3

Perhaps the closest thing to what you want is to use HoldForm to prevent the sorting behavior of Times due to Orderless: str = "one Test String to see"; HoldForm @@ MakeExpression @ str one Test String to see However it is important to realize that the HoldForm head is still present, only that it is not shown in standard formatted output. Also know ...


2

My way for this is: eq = (x - a)^2 + (y - b)^2 + (z - c)^2 + d; eq == 0 /. Solve[ForAll[{x, y, z}, -11 - 2 x + x^2 - 4 y + y^2 - 6 z + z^2 == eq]] // TraditionalForm (* {(x-1)^2+(y-2)^2+(z-3)^2-25} *)


2

FromDigits /@ StringSplit["1 2 3 4 5 6"] ToExpression@StringSplit["1 2 3 4 5 6"] StringCases["1 2 3 4 5 6", ns : NumberString :> FromDigits[ns]] ToExpression@StringCases["1 2 3 4 5 6", NumberString] all give (* {1, 2, 3, 4, 5, 6} *)


2

res = ToExpression@StringSplit["1 2 3 4 5 6", " "] {1, 2, 3, 4, 5, 6} Head /@ res {Integer, Integer, Integer, Integer, Integer, Integer}


2

Flatten[ImportString["1 2 3 4 5 6", "Table"]] {1,2,3,4,5,6} Head /@ % {Integer, Integer, Integer, Integer, Integer, Integer}


2

You can start by simply creating a function that tests, whether a string is a list of rules or not isTransformable[str_String] := SyntaxQ[str] && MatchQ[MakeExpression[str], HoldComplete[{_Rule ..}]]; isTransformable[___] := False; Note that this function does much more that search for a "->" inside a string. First, it tests, whether the ...


1

I don't quite understand your code, especially the key_/;key->val_ part, but the following code shall do your work: ToExpression@str //. key_String /; StringMatchQ[key, ___ ~~ "->" ~~ ___] :> ToExpression[key]


1

ToExpression["{" <> StringReplace["1 2 3 4 5 6", " " -> ","] <> "}"]



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