MathGroup Archive 2010

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

Search the Archive

Re: Splitting string by patterns

  • To: mathgroup at
  • Subject: [mg109701] Re: Splitting string by patterns
  • From: Albert Retey <awnl at>
  • Date: Wed, 12 May 2010 07:35:13 -0400 (EDT)
  • References: <hsbbdt$jjp$>


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

I think that what you want is StringTake. It will accept a list of
begin-end position pairs which you can e.g. create from your positions
with Partition as I have done below:

StringTake[longstring, Partition[Flatten[{1, position, -1}], 2, 1]]

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

I think you should be able to use StringSplit, I wonder what you can
achieve with StringPosition that you cannot with StringSplit. Note that
StringSplit accepts arbitrary StringPatterns or RegularExpressions as a
second argument...



  • Prev by Date: Re: Discrete Fourier Transform
  • Next by Date: Re: implicit function
  • Previous by thread: Splitting string by patterns
  • Next by thread: Part specification... is neither an integer nor a list of integers