MathGroup Archive 2001

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

Search the Archive

Re: metacharacters as record separators


Aaron:

I've needed to do this a few times and I've used variations on the
function called parse that appears below.  In this case the dollar sign
is used as a separator, but with a little bit more programming you could
have a family of separators.

Good luck

Ken Levasseur
Math Sciences
UMass Lowell

In[1]:=
!! example.txt
name1$address1$city1$state1$phone1
name2$address2$city2$state2$phone2
In[2]:=
OpenRead["example.txt"]
Out[2]=
InputStream[example.txt, 10]
In[3]:=
somelines = ReadList["example.txt", String]
Out[3]=
{name1$address1$city1$state1$phone1,
  name2$address2$city2$state2$phone2}
In[4]:=
parse[s_String] :=
  Map[StringJoin, ({Characters[
            s]} //. {{p___, {a___, "$", b___}} :> {p, {a}, {b}}})]
In[5]:=
Map[parse, somelines]
Out[5]=
{{name1, address1, city1, state1, phone1},

  {name2, address2, city2, state2, phone2}}

"Aaron E. Hirsh" wrote:

> Is it possible to use metacharacters as part of record separators in
> ReadList? For example, can one separate data at each occurrence of a
> number, or at each occurrence of a character other than an uppercase
> letter?
>
> Many Thanks,
>
> Aaron Hirsh
> --
>
> Aaron E. Hirsh
> Center for Computational Genetics and Biological Modeling
> Stanford University
> tel. (650) 723-4952
> fax (650) 725-0180



  • Prev by Date: Re: Napoleon
  • Next by Date: Re: Functions and Packages
  • Previous by thread: metacharacters as record separators
  • Next by thread: Re: metacharacters as record separators