MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: StringCases matching on portions of sublist?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106695] Re: [mg106646] StringCases matching on portions of sublist?
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 21 Jan 2010 04:53:43 -0500 (EST)
  • Reply-to: hanlonr at cox.net

z = {
   {"Thu Nov 19 12:09:23 GMT 2009", 7492, 0, 0},
   {"Thu Jan 07 13:48:21 GMT 2010", 9225, 3, 0},
   {"Thu Dec 17 09:30:52 GMT 2009", 8735, 1, 0}};

Select[z, StringMatchQ[#[[1]], "*Nov*"] &]

{{"Thu Nov 19 12:09:23 GMT 2009", 7492, 0, 
     0}}

Cases[z, _?(StringMatchQ[#[[1]], "*Nov*"] &)]

{{"Thu Nov 19 12:09:23 GMT 2009", 7492, 0, 
     0}}


Bob Hanlon

---- Jason Ledbetter <jasonbrent at gmail.com> wrote: 

=============
Folk,

I'm trying to write a function to narrow down some data by timestamp but I'm
having some trouble getting this to work.

My data is a list of lists with the first member of each sublist being a
date stamp. I was hoping to use StringCases to match but I'm apparently
missing something here.

Example data is as follows:

z={{"Thu Nov 19 12:09:23 GMT 2009", 7492, 0,
  0}, {"Thu Jan 07 13:48:21 GMT 2010", 9225, 3,
  0}, {"Thu Dec 17 09:30:52 GMT 2009", 8735, 1, 0}}


I've tried the following:


StringCases[z, {"*Nov",___}]


which returns:


String or list of strings expected at position 1 in StringCases. This makes
sense to me.. so I tried:


StringCases[z[[All,1]], ___~~Nov~~___]


which returns:


{{"Thu Nov 19 12:09:23 GMT 2009"}, {}, {}}


How can this be modified to return the full sublist where the first element
of the sublist matches a string pattern?


-jbl



  • Prev by Date: NotebookGet/Read/EvaluateSelection Issues
  • Next by Date: Re: exporting numerical data
  • Previous by thread: Re: StringCases matching on portions of sublist?
  • Next by thread: Sorting paired columns of dates and values