MathGroup Archive 2006

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

Search the Archive

Re: Position

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67671] Re: Position
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Tue, 4 Jul 2006 01:57:27 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 7/3/06 at 6:37 AM, vze269bv at verizon.net (Bruce Colletti) wrote:

>Let X be a list of strings having diverse lengths (some are the null
>string "").

>What command returns the position in X of the first element that
>starts with "abcd"?

>Presumably the command looks like Position[X,...,Heads->False], but
>my attempts have come up dry.  Although StringTake[Y,4]=="abcd"
>would seem to be part of the command, this fails when the string's
>length is less than 4.

It seems to me, what you want is StringPosition, i.e..

In[3]:=
StringPosition[#,"bc"]&/@{"abd","abcd","","bc"}

In[3]:=
(StringPosition[#1, "bc"] & ) /@ {"abd", "abcd", "", "bc"}

Out[3]=
{{}, {{2, 3}}, {}, {{1, 2}}}
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: StringReplace and WordBoundary
  • Next by Date: Elliptic integral
  • Previous by thread: Re: Position
  • Next by thread: RE: Position