文本文档数据的读取问题 ( 积分: 150 )

  • 主题发起人 主题发起人 Frank_wu
  • 开始时间 开始时间
F

Frank_wu

Unregistered / Unconfirmed
GUEST, unregistred user!
读取文本文档中的数据,但是这个文本文档里的内容、格式不定:如<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 梁内力<br> 节点 &nbsp;弯矩1 &nbsp;弯矩2 &nbsp;弯矩3 &nbsp;弯矩4 弯矩5 &nbsp;弯矩6 弯矩7 <br> 0.8 &nbsp; &nbsp;-0.9 &nbsp;1.2 &nbsp; &nbsp; 1.4 &nbsp; -1.6 &nbsp; -1.8 &nbsp;3.0 &nbsp; 49.86<br><br>怎么读这些数据。数据是可变的。<br>下面是我写的一种一行7个数据的方法,但是满足不了文本文档里的内容、格式不定这个要求<br>请高手指教。。。。。
 
读取文本文档中的数据,但是这个文本文档里的内容、格式不定:如<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 梁内力<br> 节点 &nbsp;弯矩1 &nbsp;弯矩2 &nbsp;弯矩3 &nbsp;弯矩4 弯矩5 &nbsp;弯矩6 弯矩7 <br> 0.8 &nbsp; &nbsp;-0.9 &nbsp;1.2 &nbsp; &nbsp; 1.4 &nbsp; -1.6 &nbsp; -1.8 &nbsp;3.0 &nbsp; 49.86<br><br>怎么读这些数据。数据是可变的。<br>下面是我写的一种一行7个数据的方法,但是满足不了文本文档里的内容、格式不定这个要求<br>请高手指教。。。。。
 
var<br> &nbsp;F: TextFile;<br> &nbsp;S,temp: string;<br> &nbsp;arr:array[0..300] of string;<br> &nbsp;str:array[0..255] of char;<br> &nbsp;i,j,m,k,n:integer;<br>begin<br> &nbsp;i:=0;j:=0;m:=0;n:=0;<br> &nbsp;k:=0;<br> &nbsp;if OpenDialog1.Execute then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ Display Open dialog box }<br> &nbsp;begin<br> &nbsp; &nbsp;AssignFile(F, OpenDialog1.FileName); { File selected in dialog }<br> &nbsp; &nbsp;Reset(F);<br> &nbsp; &nbsp;Readln(F, S);<br> &nbsp; &nbsp;if StrPos(PChar(s),PChar('qq'))&lt;&gt;nil then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;while not eof(F) do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Readln(F, S);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if StrPos(PChar(s),'**恒载内力**') &lt;&gt;nil then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;/////////////<br> &nbsp; &nbsp;Readln(F,S);<br> &nbsp; &nbsp;while StrPos(PChar(s),'ww')=nil do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;Readln(F, S);<br> &nbsp; &nbsp; &nbsp;if StrPos(PChar(s),'-- 柱')&lt;&gt;nil then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;Readln(F,S);<br> &nbsp; &nbsp; &nbsp; &nbsp;while StrPos(PChar(s),'--')=nil do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; ////<br> &nbsp; &nbsp; &nbsp; &nbsp; //showmessage(S);<br><br> &nbsp; &nbsp; &nbsp; &nbsp; StrPcopy(str,S);<br> &nbsp; &nbsp; &nbsp; &nbsp; //str:=PChar(S);<br> &nbsp; &nbsp; &nbsp; &nbsp; //showmessage(s[7]);<br><br><br> &nbsp; &nbsp; &nbsp; &nbsp; /////////////<br> &nbsp; &nbsp; &nbsp; &nbsp; for i:=0 to (Strlen(str)-1) do<br> &nbsp; &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (CompareStr(str,' ')=0) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (CompareStr(str[i+1],' ')&lt;&gt;0) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m:=i+1;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;///////////////<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (CompareStr(str,' ')&lt;&gt;0) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (CompareStr(str[i+1],' ')=0) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n:=i;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//showmessage(Copy(str,m,(n-m+2)));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;temp:=Copy(str,m,(n-m+2));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;arr[k]:=temp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;k:=k+1;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//////////<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; end;<br> &nbsp; &nbsp; &nbsp; &nbsp; Readln(F,S);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;showmessage(arr[6]);<br><br> &nbsp; &nbsp;CloseFile(F);<br> &nbsp;end;<br><br>end;
 
这种方法可以读一行7个数据。但是满足不了要求,请教大虾!
 
我想你的思路不明确.<br><br>readln(f,s);<br>s:=trim(s);<br>i:=0;<br> while pos(' ',s)&gt;0 do<br> &nbsp;begin<br> &nbsp; &nbsp;arr:=Copy(s,1,pos(' ',s)-1);<br> &nbsp; &nbsp;delete(s,1,pos(' ',s));<br> &nbsp; &nbsp;s:=trim(s);<br> &nbsp; &nbsp;i:=i+1;<br> &nbsp;end;
 
后退
顶部