New answers tagged

1

Example: URLSave @ "http://geniusquotes.org/wp-content/uploads/2014/06/The-quieter-you-become.jpg" Reference: URLSave Tutorial: Web Operations


4

You are correct, StringCases does not support abbreviated string patterns. Abbreviated string patterns date back to Mathematica version 1. StringExpression was introduced in Mathematica version 5.1, largely obsoleting abbreviated patterns for string manipulation functions. They still remain useful in other contexts such as file and symbol name ...


4

You are not missing anything. The documentation for StringCases does not state that it supports abbreviated expressions while StringMatchQ does. But you can use a string expression. StringCases["MATCH", ___ ~~ "H"] (* {"MATCH"} *)


3

Thanks to andre's comment (where this link is provided), I now see the effect of those delimiters. If I add 2 newlines to the box representation of the cell: Cell[BoxData["\"\<a bc\>\""], "Input", CellChangeTimes->{{3.662918813714031*^9, 3.6629188530623317`*^9}}] and switch back using Shift+Ctrl+E, then the cell look like this: "a bc" But ...


0

You can also try: StringTemplate["Number: `1` some other text"] [ToString[NumberForm[N[Pi], {\[Infinity], 2}]]] That is, leave the formatting to ToString, which does handle NumberForm and everything else.


3

It won't happen only at the end of the encoding but rather every 76 characters resulting from the encoding. For many old programs that couldn't handle reading long lines, introducing a newline character was introduced every certain number of characters. In computer science argot this is called text wrapping. I guess that the number 76 of characters comes ...


6

An attempt at a purely string-processing approach: elem = Alternatives @@ Reverse @ SortBy[StringLength] @ Array[ElementData[#, "Symbol"] &, 112]; chem = StringCases[#, e : elem ~~ n : DigitCharacter ... :> {e, n}] /. "" -> "1" &; chem @ {"Fe3O4", "CH3Cl"} {{{"Fe", "3"}, {"O", "4"}}, {{"C", 1}, {"H", "3"}, {"Cl", "1"}}}


7

Here is an example of how to work with chemicals the Mathematica way. First we retrieve the entity corresponding to the chemical: Then, if we don't know them by heart, we check out the available properties for chemicals: EntityProperties["Chemical"] This returns a long list of properties. There is one called "element counts" that seems interesting. We ...


3

I think this is only a dislay issue: If you set x=3231.432 you also get 3231.42 as a return. However, if you evaluate, say, x-3000 the missing digit (2) will appear again. I guess Mathematica only displays five significant figures (per default). Hope this helps.


1

SearchAll[sequence_, search_] := Module[{map}, map = Map[# -> "\!\(\*StyleBox[\"" <> # <> "\",FontColor->" <> ToString@RGBColor[RandomReal[], RandomReal[], RandomReal[]] <> "]\)" & , search]; StringReplace[sequence, map]] SearchAll["CGACATCACCGATGGGGAAGATCGGGCTCGCCACTTCGGGCTCATGA", {"CGA", "CATG"}] // Style[#, ...


2

As discussed in comments, we can get the result directly. StringCases["tthis is a book fine", Repeated /@ {"is", "book", "t"}] {"tt","is","is","book"}


4

This problem appears to be localized to HTMLFragment, possibly because HTML specifications before HTML5 did not use self-closing tags like XHTML and XML always have. Exporting the string as XML appears to solve the problem: ExportString[XMLElement["test", {"attr" -> "val"}, {}], "XML"] "<test attr='val' />"


2

There are a number of ways this could be done, e.g. list /. {_Missing, _} :> Sequence[] or missing any position: list/. {___, _Missing, ___} :> Sequence[] or Cases[list, Except[{___, _Missing, ___}]] DeleteCases[list, {___, _Missing, ___}] Select[list,FreeQ[Missing][#]==True&] Pick[list, FreeQ[Missing] /@ list] True /. GroupBy[list, ...


2

At the cost of an extra space character (will be ignored in an html-context AFAIK): ExportString[XMLElement["input", {}, {" "}], "HTMLFragment"] "<input class=\"form-control\"> </input>" of course that does unlike your suggestion also create the closing tag, but you probably don't want to create non-XHTML-conform html-fragments these ...


0

Code: (*data*) list = {{a, b}, {Missing["not available"], c}, {d, e}}; Select[DeleteMissing @ # & /@ list, Length @ # == 2 &] Output: (*{{a, b}, {d, e}}*) Reference: Select DeleteMissing Length


2

Edit take 2: this turns out bit cleaner. As we read each block look for characters at the end that might be the beginning of a match and push those to the next block. Export["test.txt", input = "manmanman"] infile = OpenRead["test.txt"]; outfile = OpenWrite["out.txt"]; subs = "man" (* strings only, no string expressions *) repl = "woman" block = 5; (*for ...



Top 50 recent answers are included