MathGroup Archive 2009

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96184] Re: [mg96170] How to get position of string in a mixed list? (string
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Mon, 9 Feb 2009 05:31:14 -0500 (EST)
  • References: <200902070854.DAA24760@smc.vnet.net>
  • Reply-to: drmajorbob at longhorns.com

data = {"a", "abc", "dfe", "nab", 1, 2, 3, {1, 2}};
Cases[data, x_String]
Select[%, StringMatchQ[#, ___ ~~ "ab" ~~ ___] &]

{"a", "abc", "dfe", "nab"}

{"abc", "nab"}

or

Select[data, StringQ[#] && StringMatchQ[#, ___ ~~ "ab" ~~ ___] &]

{"abc", "nab"}

Bobby

On Sat, 07 Feb 2009 02:54:13 -0600, 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.
>



-- 
DrMajorBob at longhorns.com


  • Prev by Date: Re: Re: FindFit & NIntegrate
  • Next by Date: Re: How to get position of string in a mixed list? (string pattern
  • Previous by thread: How to get position of string in a mixed list? (string pattern in
  • Next by thread: Re: How to get position of string in a mixed list? (string pattern in