MathGroup Archive 2006

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

Search the Archive

Re: Position

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67667] Re: Position
  • From: "Scout" <Scout at nodomain.com>
  • Date: Tue, 4 Jul 2006 01:56:56 -0400 (EDT)
  • References: <e8ashi$g8j$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Bruce Colletti" <vze269bv at verizon.net>
 news:e8ashi$g8j$1 at smc.vnet.net...
> 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.
>
> Thankx.
>
> Bruce
>
>
>
Hi Bruce,
this may help you. It's not too elegant but it does the job:

    In[1]:= x ={"one","two","three","four","five","six","seven"};
    In[2]:= sub1="f";

    In[3]:= Position[x,#]&/@Select[x,StringMatchQ[#,sub1~~___]&,1]//Flatten
    Out[3]= {4}

    In[4]:= sub2="eleven";
    In[5]:= Position[x,#]&/@Select[x,StringMatchQ[#,sub2~~___]&,1]//Flatten
    Out[5]={}


Regards,
    ~Scout~


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