Tag Info

Hot answers tagged

11

Not much to say here other than this is a nasty bug, but since you seemed to be curious what exactly goes wrong, here's the function that does the formatting: This function breaks the number into integer and fractional parts, converts both to a string (as integers) and joins them with a decimal point. The integer part of -0.5 is 0 which is formatted as ...


9

QuantityMagnitude[WolframAlpha[#, {{"Result", 1}, "ComputableData"}]] & /@ {"Apple company revenue", "Apple company interest expense", "Apple company employees"} (* {1.828*10^11, 3.84*10^8, 97000} *) Update: Exchange rate conversion WolframAlpha[#, {{"Result", 1}, "ComputableData"}] & /@ {"Sony company revenue", "Sony company interest ...


9

Here is a method using StringSplit and RegularExpression: StringSplit[systemNames, RegularExpression["(?=[$[:upper:]])"]] (* {{A,A,S,Triangle},{Abelian,Group},{Abort},{Abort,Kernels},{Abort,Protect}, {Above},{Abs},<<5192>>,{$,User,Documents,Directory},{$,User,Name},{$,Version}, {$,Version,Number},{$,Wolfram,I,D},{$,Wolfram,U,U,I,D}} ...


8

You can do all of it directly with StringCases! StringCases[systemNames, hump : (CharacterRange["A", "Z"] | DigitCharacter) | "$" ~~ restOfCamel : CharacterRange["a", "z"] ...] (* {{A,A,S,Triangle},{Abelian,Group},{Abort},{Abort,Kernels},{Abort,Protect}, {Above},{Abs}, ...5182... ,{$,User,Base,Directory}, ...


5

The rules seem to be amenable to a recursive regular expression: extract[s_] := StringCases[s, RegularExpression["b|c|(a(?R)*d)"]] extract["abdcbaacdabbdd"] (* {"abd", "c", "b", "aacdabbdd"} *) Further examples: extract["b"] (* {"b"} *) extract["bcbbc"] (* {"b", "c", "b", "b", "c"} *) extract["ad"] ...


4

I was able to match your example, but I'm not sure I completely grasped the problem! exampleStr = "abdcbaacdabbdd" checkSubStr[str_String] := And @@ ((Count[Take[Characters@str, #], "a"] >= Count[Take[Characters@str, #], "d"]) & /@ Range[StringLength@str]) StringCases[exampleStr, Shortest@ tot : ("b" | "c" | (x : ("a" ~~ ___ ~~ "d")) /; ...


3

Regular expressions are cryptic, but they offer look-ahead and look-behind capabilities that are unavailable to regular string patterns: split[s_] := StringSplit[s, RegularExpression["( |,|(?<![[:alpha:]])[-.]|[-.](?![[:alpha:]]))+"]] split[",,temp sp.a tiral - dump NV-A rambo.6833. 16,rgcht"] (* {"temp", "sp.a", "tiral", "dump", "NV-A", "rambo", ...


3

Introduction There are a few ways to make such a table: (1) a symbolic way that seems conceptually clear and whose slowness is not prohibitive for a table of at most a few thousand entries; (2) using the table created by NDSolve in solving the equation by integrating its derivative either (a) directly or (b) correcting the errors in it; and (3) making a ...


2

I'll try to address this one step at a time. Since a is assigned a value of 0.022 I shall assume we will be working numerically. Let's plot our function. a = 0.022; expr = (1/2) x Sqrt[1 + 4 a^2 x^2] + ArcSinh[2 a x]/(4 a) Plot[expr, {x, -1*^5, 1*^5}] 1/2 x Sqrt[1 + 0.001936 x^2] + 11.3636 ArcSinh[0.044 x] There appear to be no complications so ...


2

Not anyhere elegant as the OP's own method, but ... staying in the String universe may be a good alternative. Stealing @Aisamu's string pattern and using only String functions: ClearAll[cssF, strngCF]; cssF = Function[{s}, And @@ Flatten[{Equal @@ (StringCount[s, #] & /@ {"a", "d"}), (StringCount[#, "a"] >= StringCount[#, "d"] ...


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

Thank you for a well-written question with complete code that made this reasonable to answer. Welcome to Mathematica Stack Exchange. :-) You do not need UpValues definitions here. That would only apply if you were attempting to add a rule to e.g. Plus rather than Sup, yet your use of TagSetDelayed makes it clear that you are attaching the rule to Sup. ...


1

There's special function for generating fortran-like forms: SetOptions[$Output, PageWidth -> 100] FortranForm[string] And certainly you can manage string manually. To insert new strings in the string you can write something like this: string = StringJoin[ToString /@ Range[1000]]; step = 10 StringInsert[string, "&&\n&&", Range[step, ...


1

Import["binary.txt"] in this case is equivalent to Import["binary.txt", "Text"] not to Import["binary.txt", "String"] Documentation states that Import["binary.txt"] "reads a text file, taking the character encoding to be "UTF8" by default." Whereas for format "String" documentation states that "imports a raw sequence of bytes and returns them as a ...


1

trialtext = ",,temp sp.a tiral - dump NV-A rambo.6833. 16,rgcht"; StringTrim@StringSplit[trialtext, {"," | "-" | ".", x : PatternSequence[Except[WhitespaceCharacter] .. ~~ "." | "-" ~~LetterCharacter ..] :> x}] (* {"temp", "sp.a", "tiral", "dump", "NV-A", "rambo", "6833", "16", "rgcht"} *)



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