MathGroup Archive 2009

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

Search the Archive

Re: Finding the Position of Elements in a List that Contain


Hi Mitch,

Thanks for responding.  StringPosition is not the thing because it  
gives me the location of the search string within the target string.   
I want to identify which of the target strings, namely, 1 and 4,  
contain the word cat as a distinct word, and failing that, also  
include it as a substring (catalogue).

Regards,

	Gregory


On 31-Jul-09, at 9:22 AM, Mitch Stonehocker wrote:

> Is this what you're after?
>
> In[1]:= listOfStrings = {"The cat is here.", "It's not here.",
>   "Not in the catalogue,", "Where is the cat?"};
>
> In[2]:= searchString = "cat";
>
> In[3]:= StringPosition[listOfStrings, searchString]
>
> Out[3]= {{{5, 7}}, {}, {{12, 14}}, {{14, 16}}}
>
> Cheers,
> Mitch



  • Prev by Date: Assume and $Assumptions and Results
  • Next by Date: Re: Help with concatenating a list with &&
  • Previous by thread: Re: Re: Assume and $Assumptions and Results
  • Next by thread: Re: Finding the Position of Elements in a List that Contain