# Tag Info

6

On the second line, the string that looks like "in" is in fact a three-character string. The third character is a soft-hyphen: it is invisible and it is used to mark a position where a word can be hyphenated. It has character code 173. StringReplace finds no match due to this invisible third character. You can detect this using FullForm or ...

2

I found the problem is with my original data; there are some unexpected Line Feed characters in my data which were causing me to misinterpret the result of "Import" using type CSV. The comments by Yode and JasonB prompted me to look at the file with notepad++ so I could see the LF characters. Sorry for the confusion.

4

This looks like a job for associations: input = "article{a2,author={F1name L1name,F2name M2name,L2name}, title={The title of the work}, journal={The Journal2},year=1994, number=3,pages={204-223},month=6, note={An optional note},volume=2}" type = StringCases[input, Shortest[StartOfString ~~ t : __ ~~ "{"] :> t][[1]] "article" key = ...

3

You can replace your TemplateApply with either TemplateApply["Print[];", i++] or StringJoin["Print[", ToString[i++], "];"] There is also a quick fix that is not recommended, which is to replace Module by Block.

4

There are two differences between Write and WriteString: Write adds a newline after all expressions, WriteString does not. Write uses the FormatType of the output stream (default InputForm), WriteString uses OutputForm. WriteString does not require its argument to be a string. Therefore, the simplest fix is to just change the second Write to WriteString....

3

To further simplify the old code and make it fully robust (since among other things VectorQ[{}, NumberQ] returns True): ValidCASNumberQ[n_String] := With[{l = StringCases[n, x : DigitCharacter :> FromDigits[x]]}, 4 < Length[l] <= 10 && Mod[Reverse[Most[l]].Range[Length[l] - 1], 10] == Last[l]] StringCases[] guarantees that ...

1

Here is a slightly modified version of the function from the linked package ValidCASNumberQ[n_Integer] := Block[ {d = IntegerDigits[n]}, Mod[Most[d].Range[Length[d] - 1, 1, -1], 10] == Last[d]] ValidCASNumberQ[n_String] := Block[{ l = StringCases[StringDelete[n, "CAS"], x : DigitCharacter :> FromDigits[x]], }, If[! VectorQ[l, NumberQ],...

1

casQ[CASRN_] /; MatchQ[CASRN, _String | _Integer]:= Module[{digits, count}, digits = If[IntegerQ@CASRN, IntegerDigits[CASRN], StringCases[CASRN, x : DigitCharacter :> FromDigits[x]]]; count = Length@digits; count > 4 && count < 11 && Last@digits == Mod[Reverse@Drop[digits, -1].Range[count - 1],...

1

For (6) you need to specify two patterns, one for each ordering: words = {"abcd", "aydx", "axdy", "adx"}; Select[ words, StringContainsQ[("x" ~~ ___ ~~ "y") | ("y" ~~ ___ ~~ "x")] ] (* Out: {"aydx", "axdy"} *) StringContainsQ, StringStartsQ and StringEndQ can be used for some of your patterns and may either give a performance boost or at the very ...

1

As of version 10.1 there is TextWords that will achieve this for you easily TextWords[",,temp sp.a tiral - dump NV-A rambo.6833. 16,rgcht"] (*{"temp", "sp.a", "tiral", "dump", "NV-A", "rambo.6833", "16,rgcht"}*) Note that the implementation of the function is available to you with ??TextWords It relies on a bunch of stuff from the ...

2

a good use for the "new in 10" StringTemplate : Table[ StringTemplate["D:\\20160615\\20160615-1-2.asc"][i, j], {i, 3}, {j, 3}] incedentally, if you need to zero pad your numbers as they often occur in file names you can use this mess: Table[ StringTemplate[ "D:\\20160615\\20160615-<*TemplateExpression[IntegerString[1,10,2]]*>-`...

4

It seems that a simple modification of your code will work. fileList[prefix_String, m_Integer, n_Integer] := With[{dash = "-"}, prefix <> dash <> ToString[#] <> dash <> ToString[n] <> ".asc"] & /@ Range[m] Then fileList["D:\\20160615\\20160615", 5, 1] gives {"D:\\20160615\\20160615-1-1.asc", "D:\\20160615\...

3

I don't think that StringMatchQ["x", Except[{"*"}]] works as expected as well as StringMatchQ["x", Except["*"]]: StringMatchQ["x", Except[{"*"}]] StringMatchQ["x", Except["*"]] True True The string pattern "*" is an abbreviated string pattern consisted from the only metacharacter * which corresponds to zero or more characters according to the first ...

12

For large lists, this should be snappy: Pick[Range@Length@dat, StringTake[dat, UpTo@4], "star"] and actually, taking advantage of listability, Pick[Range@Length@dat, StringMatchQ[dat, "star*"]] is a bit faster it seems...

10

Position[dat, _String?(StringMatchQ[#, "star" ~~ ___] &)] or Position[dat, _String?(StringMatchQ[#, "star*"] &)] or Position[dat, _?(StringMatchQ[#, "star*"] &), Heads -> False] or Position[StringMatchQ[dat, "star*"], True] (*thanks: @TomD *) {{1}, {7}, {13}, {19}} Alternatively, Pick[Range@Length@dat, StringMatchQ[#, "star*"] ...

1

In order to perform the Manipulate that you are looking for we really only need three functions (see Feyre's comment). My interpretation is that you could use: kbA[θ_] := 6.80414/((θ/10 - 0.119974) Sqrt[-1.19974 + θ]) kbM[θ_] := 37037/(20.468 + 22.4478 θ + 8.2063 θ^2 + θ^3) cfun[kA_, kM_] := kA^(1/3) + kM^(2/3) - 8 (kA + kM)/100 Now we can define your ...

4

Get the relation graph of your example graph = SimpleGraph[RelationGraph[StringStartsQ, example], VertexLabels -> "Name"] Get the end of the vertex in every weaky connected graph First@*TopologicalSort/@WeaklyConnectedGraphComponents[graph] {"Clothing/Accessories/Belts", "Watches/Accessories/Pocket Watch Chains"} Hope this can help. :)

3

EDIT: My original answer, while quite a bit quicker than the current answer, dropped some words that should not be dropped, as does the other current answer, e.g.. {"pa","paperweight"} fails on both (unless that is the intent of the OP, which I doubt). This led me to the following, which does not suffer from the problem and is also quite a bit quicker yet: ...

4

Your solution doesn't seem to work when there are duplicates. Anyway, could you test the performance of the following method? example = RandomChoice[{"Clothing", "Clothing/Accessories", "Clothing/Accessories/Belts", "Watch", "Watches/Accessories", "Watches/Accessories/Pocket Watch Chains" }, 15000 ]; Split[Sort@example, StringStartsQ[#2, #] &...

1

I use code from J.M comment, and it works perfectly text = {"რომელმან", "შექმნა", "სამყარო", "ძალითა", "მით", "ძლიერითა", "ზეგარდმო", "არსნი", "სულითა", "ყვნა", "ზეცით", "მონაბერითა", "ჩვენ", "კაცთა", "მოგვცა", "ქვეყანა", "გვაქვს", "უთვალავი", "ფერითა", "მისგან", "არს", "ყოვლი", "ხელმწიფე", "სახითა", "მის", "მიერითა"} LetterCounts[StringRiffle[text]] ...

8

bin = 1011011; words = (bin // IntegerDigits) /. {1 -> "one", 0 -> "zero"}; (str = StringJoin[Riffle[words, " "]]) // InputForm (* "one zero one one zero one one" *) Speak[str]

3

Since space is implicit Times similar methods to Convert head Times to List can be applied: Block[{Times = List}, ToExpression @ "{1 2 3 4 5 6 7 8}"] // First {1, 2, 3, 4, 5, 6, 7, 8} Though in this case a much shorter method works too: ToHeldExpression[expression] ~Level~ {3} {1, 2, 3, 4, 5, 6, 7, 8}

Top 50 recent answers are included