MathGroup Archive 2006

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

Search the Archive

Re: Position

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67685] Re: [mg67639] Position
  • From: gardyloo <gardyloo at mail.wsu.edu>
  • Date: Tue, 4 Jul 2006 01:58:37 -0400 (EDT)
  • References: <200607031037.GAA16424@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi, Bruce.

   This works for me:

In[1]:=
testlist = {"a string1", "a string2", "abcde", "avcfgehi", "1234",
   "abcd12345", "ab", "1", "", "", "abcdefghi"};

In[2]:=
extractABCD[st_String] := If[StringLength[st] >= 4, StringTake[st, 4]]

In[3]:=
extractABCD /@ testlist

Out[3]=
{"a st", "a st", "abcd", "avcf", "1234", "abcd", Null, Null, Null, Null,
  "abcd"}

In[4]:=
Flatten[Position[extractABCD /@ testlist, "abcd", 1, 1]]

Out[4]=
{3}


            Hope that helps!
                           Curtis O.


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.
>
> Thankx.
>
> Bruce
>
>  
>
>
>   

-- 
==========================================================
Curtis Osterhoudt          
gardyloo at mail.remove_this.wsu.and_this.edu
PGP Key ID: 0x088E6D7A
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================================================


  • References:
    • Position
      • From: Bruce Colletti <vze269bv@verizon.net>
  • Prev by Date: RE: Re: Re: Re: Limit of an expression?
  • Next by Date: Iterated Function System
  • Previous by thread: Position
  • Next by thread: Re: Position