delphi读一个txt文件,如何逐字分析

来源:百度知道 编辑:UC知道 时间:2024/06/09 08:55:09
比如读取F:\a.txt文件,内容如下
ENTITY activity
SUBTYPE OF
(
e_and_p_data
);
activity_context : OPTIONAL locatable_object;
containing_activity : OPTIONAL activity;
cost : OPTIONAL ndt_money;
duration : OPTIONAL ndt_time;
end_time : OPTIONAL ndt_date_tod;
identifier : ndt_identifier;
kind : activity_class;
naming_system : OPTIONAL naming_system;
ref_existence_kind : ref_existence_kind;
ref_transient_period : OPTIONAL ref_transient_period;
start_time : OPTIONAL ndt_date_tod;
想每个词每个词再拿出来去生成其他的文件。
主要是问怎么把每个词拿出来?
一行一行读出来,然后通过空格分拆

假设a.txt其在c盘根目录下

procedure TForm1.Button1Click(Sender: TObject);
var
sl:TStringlist;
sltemp:TStringList;
i:integer; //遍历每行
j:integer; //遍历每行以空格拆分的字符串
begin
sl:=TStringlist.Create; //存储载入的文本文件
sltemp:= TStringlist.Create; //存储每行的内容

sl.LoadFromFile('c:\a.txt'); //把文件载入变量sl
for i:=0 to sl.Count-1 do //逐行处理
begin
sltemp.Clear;
sltemp.CommaText:=sl.Strings[i];
for j:=0 to sltemp.Count-1 do
showmessage(sltemp.Strings[j]); //取出并显示每个字符串
end;

sl.Free;
sltemp.Free;
end;