Re: Finding the Position of Elements in a List that Contain
- To: mathgroup at smc.vnet.net
- Subject: [mg102194] Re: [mg102157] Finding the Position of Elements in a List that Contain
- From: Gregory Lypny <gregory.lypny at videotron.ca>
- Date: Sat, 1 Aug 2009 03:58:19 -0400 (EDT)
- References: <200907310953.FAA19267@smc.vnet.net>
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