MathGroup Archive 2013

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

Search the Archive

Re: find position in a list made by string by searching incomplete

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130363] Re: find position in a list made by string by searching incomplete
  • From: Peter Pein <petsie at dordos.net>
  • Date: Thu, 4 Apr 2013 22:33:16 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <kjkc5e$7mu$1@smc.vnet.net>

Am 04.04.2013 19:10, schrieb Joug Raw:
> I have a list of strings like
> list1={{"a", "b    something", "a", "a", "b", "c", "b"}
> In this list, 'something' is a sting that I will not know in advanced and
> there are several spaces between the 'b' and the 'something' in one string.
> The number of the spaces is unknown.
>
> I want to find out the position of the this "b   something" sting in the
> list. So, I did,
>
> Position[list1, "b*"]
>
> and I also tried,
> Position[list1,"b"~~___ ]
>
> both of them gave me {} as results.
>
> Also Cases[list1,"b"~~___] or Cases[list1, "b*"] does not work. I can get
> the correct position only if I give the exact "b    something" as the
> searching pattern. What is the easiest way to search with a incomplete
> string pattern in this case? Thanks for your help.
>
>

Hi Joug,

  first use StringPosition with a StringExpression as pattern. Then wrap 
a Position[] around that:

list1={"a","b    something","a","a","b","c","b","b  sth. else"};
Position[StringPosition[list1, "b "~~__], Except[{}], 1, Heads->False]

--> {{2},{8}}

Peter



  • Prev by Date: Re: "Displaying" the meaning of zero
  • Next by Date: Re: Solve without vars
  • Previous by thread: webMathematica and Manipulate
  • Next by thread: Re: find position in a list made by string by searching incomplete