Tag Info

New answers tagged

6

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


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


0

You can use Solve for this but you have to do a little work to transform your "equation" in to a usable form. This is what my cobbled together makeExpression function does. (It also generates the conditions to ensure that the first letter of each word cannot be zero): makeExpression[expr_] := Module[{ie, r = Reap[ expr /. x_String :> ...


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


0

I guess my solution maybe pretty easy,but it can works: n = 5; ToExpression[Table["{", {n}] <> Table["}", {n}]] == Nest[{#} &, {}, n - 1] True And if I set n a large number: n=2*10^6; Nest[{#} &, {}, n]; Depth[%] 2000002 Also works.


0

Ok, that wasn't so difficult! maxBufLen = 2048; LoadNETType["System.Runtime.InteropServices.Marshal"]; buf = Marshal`AllocHGlobal[$maxBufLen]; Table[Marshal`WriteByte[buf, i, 32], {i, 0, 2048 - 1}]; sqlfunction = DefineDLLFunction["setSQL", "Server.dll", "int", {"int", "IntPtr", "int"}]; selKey = 9591556; sqlfunction[selKey, buf, maxBufLen]; managedArray ...


1

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


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


1

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


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


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


-1

Determine the potential "PartsOfSpeech" WordData["cat", "PartsOfSpeech"] {"Noun", "Verb"} then test for the type ! FreeQ[WordData["cat", "PartsOfSpeech"], "Noun"] ! FreeQ[WordData["cat", "PartsOfSpeech"], "Adjective"] ! FreeQ[WordData["cat", "PartsOfSpeech"], "Verb"] True False True Also see documentation for FreeQ. These tests may be ...


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


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


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


0

Insert the passage you want shifting as a string: str = HELLO WORLD Then, define this function: f[x_] := If[64 < x < 91, (Mod[x - 65 + s, 26] + 65), x] Where s is your shift (positive or negative). Then, simply map the function over the character codes of your string: FromCharacterCode[Map[f, ToCharacterCode[str]]] This will result in a ...



Top 50 recent answers are included