MathGroup Archive 2010

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

Search the Archive

Splitting string by patterns

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109666] Splitting string by patterns
  • From: Mauricio Esteban Cuak <cuak2000 at gmail.com>
  • Date: Tue, 11 May 2010 06:27:06 -0400 (EDT)

Dear Group:

(Version 6, Mac Os X)

This is the first time that I manipulate strings in Mathematica and I'm
getting constantly into trouble with the commands I'm familiar with, since
lists become strings, strings become lists and whatever.
I've got a long text that I need to classify in rows and columns.
Let's say that for each row I've got 3 columns. There are some collection of
words that identify rows and the different columns. The text looks somewhat
like this:

"Row 1 Identifier
text of column 1
Column 2 identifier
text of column 2
Column 3 identifier
text of column 3
Row 2 identifier
etc.
"
What I'd like as output is this:

{Row1Identifier, text of column1, text of column 2, text of column3, Row 2
Identifier, ....}

(or, finally: { {Row1Identifier, text of column1, text of column 2, text of
column3}, {Row 2 Identifier, ....}}  )

There are many possible texts that identify Rows and Columns...I already
wrote a function with StringPosition
that tells me where the Rows and Columns begin...for example:

position = {2,4,5,7,8,15,26,204}

How can I use these positions to split the long string like I want to?

Thanks for your time!

cd

P.D.: I tried to use StringSplit first (without using the positions), but to
determine the positions I'm not only using patterns, so I didn't know how to
use that function for that.


  • Prev by Date: Re: How to write reports and books in Mathematica
  • Next by Date: Part specification... is neither an integer nor a list of integers
  • Previous by thread: Re: Interference data in optica
  • Next by thread: Re: Splitting string by patterns