The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: find position in a list made by string by searching
Replies: 1   Last Post: Apr 4, 2013 10:30 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Bob Hanlon

Posts: 906
Registered: 10/29/11
Re: find position in a list made by string by searching
Posted: Apr 4, 2013 10:30 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

list1 = {"a", "b something", "a", "a", "b", "c", "b"};

pos = Position[list1, _String?(
StringLength[#] > 1 &&
StringTake[#, 1] == "b" &)]


Bob Hanlon

On Wed, Apr 3, 2013 at 10:50 PM, Joug Raw <> wrote:

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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.