Quantcast
Viewing all articles
Browse latest Browse all 188

How to extract a consecutive list of substring from a string?

Given a list of strings:

data = {"2894;Hot Pink;53:09:44;1449714","17456;Dark Cyan;19:06:42;6929227","5147;Lime;54:11:55;5247632"}

(Words are separated by ";", the number of words in strings are equal. Number of characters in strings are unequal. Number of characterss in words are unequal.)

How to extract the $m^{th}$ through $n^{th}$ words, so that e.g. $m=2, n=3$ should return:

{"Hot Pink;53:09:44","Dark Cyan;19:06:42","Lime;54:11:55"}  

UPDATE

Final solution was found for the task.
I like to share it here.

inlist = RandomChoice[{"7270;Deep Pink;04:14:55;0027354","2871;Dark Orchid;54:21:23;1182263","4021;Silver;04:00:58;6940040","3521;Dark Slate Gray;18:42:43;5828275"}, 400000];  delim = ";";fromWord = 2;numberOfWords = 2;  from = 2 fromWord - 1;to = 2 (fromWord + numberOfWords - 1) - 1;outlist = List /@ StringJoin /@      StringSplit[inlist, delim -> delim][[All, from ;; to]]; // Timing  {0.92, Null}  

The honor goes to the very concerned in this task.Every detail of their conception was vital to the solution.Keep'n rocking.


Viewing all articles
Browse latest Browse all 188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>