Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Another question Re: Mathematica 6.0 CSV export with ";" as delimiter?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80774] Re: Another question Re: Mathematica 6.0 CSV export with ";" as delimiter?
  • From: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 1 Sep 2007 00:30:13 -0400 (EDT)
  • References: <fb83ji$81t$1@smc.twtelecom.net> <46D821E7.8080607@gmail.com>

[Answer at the bottom of the post]

kirk reinholtz wrote:

> When I import this, how do I cause each field to be interpreted as a
> String, even if it looks like a number???
>
> Thanks again.
>
> On Aug 31, 2007, at 7:12 AM, Jean-Marc Gulliet wrote:
>
> > kirk reinholtz wrote:
> >> I find I need to Export a file from Mathematica 6.01  in CSV
> >> format,  except I need to use semicolon for the delimiter, rather
> >> than comma.
> >> The documentation alludes to "many options" that might influence
> >> how  this might be accomplished, but I can't find the options
> >> themselves.
> >> So please, granting I may be blind, where is this documented and
> >> how  is it done??
> > What you are really looking for is exporting a table data format
> > (file extension .dat by default) with the *FieldSeparators* option
> > set to semicolon in your case.
> >
> > In[1]:= data = RandomReal[{-1, 1}, {4, 5}]
> >
> > Out[1]= {{0.868671, -0.583131, -0.205539,
> >   0.451934, -0.179933}, {-0.892268, 0.853666, -0.936663,
> >   0.909701, -0.910825}, {-0.0781347, 0.339566,
> >   0.490868, -0.126004, -0.169031}, {0.944671,
> >   0.400847, -0.63365, -0.115168, -0.448351}}
> >
> > In[2]:= Export["myfile.dat", data, "FieldSeparators" -> ";"]
> >
> > Out[2]= "myfile.dat"
> >
> > (* and if you really insist in keeping the extension csv *)
> >
> > In[3]:= Export["myfile.csv", data, "Table", "FieldSeparators" -> ";"]
> >
> > Out[3]= "myfile.csv"

Mathematica has a built-in conversion function called *ToString* that
converts an expression into a string of characters. (The reciprocal is
*ToExpression*). Since you have a list of lists, you could use *Map*
with its third argument set to {2} (or {-1}), to apply *ToExpression*
to numbers (or atomic expressions) only. For instance,

Map[ToString, Import["myfile.dat", "FieldSeparators" -> ";"], {-1}]

-- 
Jean-Marc


  • Prev by Date: Re: Animation of a rotating object. (Mathematica 6)
  • Next by Date: Re: check inside a loop?
  • Previous by thread: Re: Re: [Mathematica 6] Bug in Labeled, Center align option
  • Next by thread: Re: check inside a loop?