Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: How to get position of string in a mixed list?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96182] Re: [mg96170] How to get position of string in a mixed list?
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Mon, 9 Feb 2009 05:30:52 -0500 (EST)
  • Reply-to: hanlonr at cox.net

list = {"a", "abc", "dfe", "nab", 1, 2, 3, {1, 2}};

Position[list, _String?(! StringFreeQ[#, "ab"] &)]

{{2}, {4}}

Position[list, _String?(StringMatchQ[#, "*ab*"] &)]

{{2}, {4}}


Bob Hanlon

---- "goodhei8 at gmail.com" <goodhei8 at gmail.com> wrote: 

=============
for list like {"a","abc","dfe","nab",1,2,3,{1,2}}, I want to get all 
strings' position in the list which match a pattern (like 
___~~"ab"~~___). How to do it? How to use a string pattern in a list 
pattern? how to use a pattern with a condition (both list pattern&/; 
StringQ[#] and list pattern /;StringQ[]&, no working for me)

Thanks.



  • Prev by Date: Re: Directory[]
  • Next by Date: Something for this list
  • Previous by thread: Stationarity tests - Dickey-Fuller, Phillips-Perron
  • Next by thread: Something for this list