Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re: metacharacters as record separators

  • To: mathgroup at
  • Subject: [mg26935] Re: [mg26881] metacharacters as record separators
  • From: Tomas Garza <tgarza01 at>
  • Date: Fri, 26 Jan 2001 23:30:11 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at

I think it would be relatively easier to perform the separation of data once
you have read your records with ReadList. This way you're already inside
Mathematica and things become smoother. Suppose you have a file of ordinary
words which you read into your notebook with ReadList:

originalList = ReadList["testwords.txt", Word]
{"Those", "friends", "thou", "hast", "\",\"", "and", "their", "adoption", \
"tried", "\",\"", "grapple", "them", "unto", "thy", "soul", "with", "hoops",
"of", "steel"}

Now suppose that you wish to separate your original records using, say, the
letter "h" as record separator:

r2 = Flatten[Characters /@ originalList]
{"T", "h", "o", "s", "e", "f", "r", "i", "e", "n", "d", "s", "t", "h", "o",
"u", "h", "a", "s", "t", "\"", ",", "\"", "a", "n", "d", "t", "h", "e", "i",
"r", "a", "d", "o", "p", "t", "i", "o", "n", "t", "r", "i", "e", "d", "\"",
",", "\"", "g", "r", "a", "p", "p", "l", "e", "t", "h", "e", "m", "u", "n",
"t", "o", "t", "h", "y", "s", "o", "u", "l", "w", "i", "t", "h", "h", "o", \
"o", "p", "s", "o", "f", "s", "t", "e", "e", "l"}

newList = {}; While[
r2 != {}, (ct = 0; If[r2 != {}, Scan[If[# != "h", ct += 1, Return[]] &, r2];
AppendTo[newList, Take[r2, ct]];
r2 = If[Length[r2] >= ct + 1, Drop[r2, ct + 1], r2 = {}]])]

StringJoin /@ newList
{"T", "osefriendst", "ou", "ast\",\"andt", "eiradoptiontried\",\"grapplet",
"emuntot", "ysoulwit", "", "oopsofsteel"}

I'm sure something more straightforward exists, but this is what came to my
mind first.

Tomas Garza
Mexico City

----- Original Message -----
From: "Aaron E. Hirsh" <aehirsh at>
To: mathgroup at
Subject: [mg26935] [mg26881] metacharacters as record separators

> 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: Functions and Packages
  • Next by Date: Re: The Integrator (Wolfram)
  • Previous by thread: Re: metacharacters as record separators
  • Next by thread: Re: metacharacters as record separators