Re: How to read a string from a file?

*To*: mathgroup at smc.vnet.net*Subject*: [mg46937] Re: How to read a string from a file?*From*: "Curt Fischer" <crf3 at po.cwru.edu>*Date*: Tue, 16 Mar 2004 19:55:01 -0500 (EST)*References*: <c36bm6$s4j$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

First, use SetDirectory[] until you get Mathematica's present working directory to be the one where your file is. Then you can do In[39]:= caption=Import["mathgroupexample.txt","Text"] Out[39]= "M=70,N=90,L=100,S0=0.0001,S1=0.1,mu=0,D=0.01,m=2,n=2,m1=2,n1=2,k1=1,k2=1,k_ 2=\ 1,k3=1,k_3=1,D1=0.01,k4=1,k_4=1,D2=0.01,k5=1,k_5=1,k6=1,k_6=1,k7=1,k_7=1,k8= 1,\ k_8=1,k9=1,k_9=1,DELTA_T=0.1,DURATION=5000000,SAMPLE_PERIOD=50000" In[40]:= linebreakcaption=StringInsert[caption,"\n",Table[i,{i,60,StringLength[captio n],60}]] Out[40]= "M=70,N=90,L=100,S0=0.0001,S1=0.1,mu=0,D=0.01,m=2,n=2,m1=2, n1=2,k1=1,k2=1,k_2=1,k3=1,k_3=1,D1=0.01,k4=1,k_4=1,D2=0.01,k 5=1,k_5=1,k6=1,k_6=1,k7=1,k_7=1,k8=1,k_8=1,k9=1,k_9=1,DELTA_ T=0.1,DURATION=5000000,SAMPLE_PERIOD=50000" In[41]:= ListPlot[{{1,1},{2,2}},PlotLabel->linebreakcaption] -- Curt Fischer Peng Yu wrote: > I have a file called outpara.txt. > The content is > "M=70,N=90,L=100,S0=0.0001,S1=0.1,mu=0,D=0.01,m=2,n=2,m1=2,n1=2,k1=1,k2=1,k_ 2=1,k3=1,k_3=1,D1=0.01,k4=1,k_4=1,D2=0.01,k5=1,k_5=1,k6=1,k_6=1,k7=1,k_7=1,k 8=1,k_8=1,k9=1,k_9=1,DELTA_T=0.1,DURATION=5000000,SAMPLE_PERIOD=50000" > > I want Mathematica read the content of the file into a string. And > then display this string as the caption of a graph generated by > ListPlot. > > I tried a few ways but it doesn't work. Could you help me?