Re: metacharacters as record separators
- To: mathgroup at smc.vnet.net
- Subject: [mg26916] Re: [mg26881] metacharacters as record separators
- From: Ken Levasseur <Kenneth_Levasseur at uml.edu>
- Date: Fri, 26 Jan 2001 23:29:56 -0500 (EST)
- References: <200101260627.BAA18724@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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
- References:
- metacharacters as record separators
- From: "Aaron E. Hirsh" <aehirsh@leland.stanford.edu>
- metacharacters as record separators