Tag Info

Hot answers tagged

10

StringTrim["ahfiehfke$jfwfjejf0", "$" ~~ __]; StringDelete["ahfiehfke$jfwfjejf0", "$" ~~ __]; (*V10.1*)


8

Perhaps, using: dateslalala={2003364, 2003157, 2003314, 2003302, 2003181, 2003062, 2003254, \ 2003070, 2003365, 2003338, 2003233, 2003073, 2003020, 2003010, \ 2003238, 2003107, 2003310, 2003347, 2003204, 2003066, 2005364, \ 2005157, 2005314, 2005302, 2005181, 2005062, 2005254, 2005070, \ 2005365, 2005338, 2005233, 2005073, 2005020, 2005010, 2005238, \ ...


6

Table[k1 + k2, Evaluate@{ToExpression[list[[1]]], 1, 2}, Evaluate@{ToExpression[list[[2]]], 1, 2}] (* {{2, 3}, {3, 4}} *) Or Table[k1 + k2, {#, 1, 2}, {#2, 1, 2}] & @@ ToExpression[list] (* {{2, 3}, {3, 4}} *)


5

You could measure the similarity between two strings. One simple approach is to convert all strings into the bag-of-words model and then compare the resulting vectors. This could work well if the strings contain the same words, but not in the same order. Nearest[vectors, x, DistanceFunction -> CosineDistance] Will give you a measure of how close ...


5

You should take a look at: New in the Wolfram Language: GrammarRules Programmable Linguistic Interface Sequence Alignment & Comparison You can also use Machine Learning to help classify strings. Here is how to train a classifier to understand if a string talks about a cat a or a dog. cat = ToLowerCase[Import["http://en.wikipedia.org/wiki/Cat"]]; ...


5

Just another way, with Templates so only for V10+: The following can be done without FileNameJoin but it is a good habit to use it: file[i] = 1; TemplateApply @ FileNameJoin[{$HomeDirectory, "Desktop", "<*file[i]*>.doc"}] ...Desktop\1.doc "<**>" is TemplateExpression


4

Here's a simple fix/workaround. It appears that all you need to do to make your code work as intended is to make the following change to your $dateFormat assignment: $dateFormat = {"Year", "", "Month", "", "Day", "", "Hour"} This generates an identical string to your test example, but it appears that the empty strings are necessary to correctly parse the ...


4

In the example you give, your Query function asks if the value at element "a" is a string match for "hey". This generates the message because the value for a is not a string in the second row of your dataset. For this particular case, one solution would be to require an exact match: data = Dataset[{<|"a" -> "hey"|>, <|"a" -> ...


4

Something like this words = DictionaryLookup[s__ /; StringFreeQ[s, "ar" | "h"]]; Length[words] 70781 sorted = SortBy[words, StringLength]; Short[sorted] {"a", "I", "AC", "ad", "AD", <<70772>>, "Andrianampoinimerina", "buckminsterfullerene", "institutionalization", "internationalization"}


3

Have a look at the documentation for CSV. The first issue you have is that your file extension is .txt so Mma imports it as text file instead of a CSV file. Your second issue is that "Table" is not a supported element for either CSV or TXT so I think it is just being ignored. Even though your file does not have the .csv file type you can still tell Mma ...


3

I'm sure this is a duplicate but to give you a quick answer here's a community wiki post: Use ToString and StringJoin to form your argument: file[i] = 1; "/Users/Home/Desktop/" <> ToString @ file[i] <> ".doc" "/Users/Home/Desktop/1.doc" Also look at FileNameJoin.


2

At the risk of betraying how long I've been using Mathematica, the method I'm accustomed to uses StringForm[] (in conjunction with ToString[] since the output of that function, nonintuitively, is not a string): file[i] = 1; OpenWrite[ToString[StringForm["/Users/Home/Desktop/`1`.doc", file[i]]]]


1

A bunch of regex methods: str = "ahfiehfke$jfwfjejf0"; (* Coolwater *) StringCases[str, RegularExpression["(?s).+?\\$", 1]][[1]] StringReplace[str, RegularExpression["(?s)\\$.*"] :> "$", 1] These use look-behind regexes: StringReplace[str, RegularExpression["(?s)(?<=\\$).+"] :> "", 1] StringTrim[str, RegularExpression["(?<=\\$).+"]] ...


1

Here is another alternative, in which the values of the variables are temporarily cleared using Block and an injector pattern. ClearAll[getSymbolNames]; SetAttributes[getSymbolNames, HoldAll]; getSymbolNames[list_Symbol] := Hold[list] /. OwnValues[list] /. Hold[{vars__Symbol}] :> Block[{vars}, SymbolName /@ {vars}] With some planning one might ...


1

Update: I haven't written any C in a long while, so I forgot its syntax for multidimensional arrays, i.e. array[first][second]! Here is the amended code: ToString[CForm[t[12, 156] + ht u[5, 3]]] StringReplace[%, { "t(" ~~ Shortest[a__] ~~ "," ~~ Shortest[b__] ~~ ")" -> "t[" ~~ a ~~ "][" ~~ b ~~ "]", "u(" ~~ Shortest[a__] ~~ "," ~~ Shortest[b__] ~~ ...


1

Doing this is pretty straightforward; you'll want to take a look at the documentation for Mathematica's string patterns primarily. As an example, to use DictionaryLookup with the "ar" and "h" instance you mention, the following are basically equivalent: matches1 = DictionaryLookup[s__ /; !StringContainsQ[s, "ar"|"h"]]; matches2 = ...


1

The thought is DatePlus. split[x_Integer] := {{FromDigits@#[[1 ;; 4]], 1, 1}, FromDigits@#[[5 ;; -1]]} &@IntegerDigits[x] split[2003305] (* {{2003,1,1},305} *) DatePlus[split[2003305][[1]], 305] (* {2003,11,2} *) f = Block[{$DateStringFormat = {"Year", "Month", "Day"}, res}, res = split[#]; DatePlus[res[[1]], res[[2]] - 1]] ...



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