文本文件中有中文就无法用

wanyuanwanyuan 2006-02-09 03:28:10
var
strlen,mytemp,counter:integer;
strtemp:string;
thefile:textfile;
mystr:array[0..13] of string;
begin
assignfile(thefile,'C:\sk_ic.txt');
reset(thefile);
read(thefile,strtemp);
closefile(thefile);
counter:=0;
while (length(strtemp)>0) or (pos(#9,strtemp)<>0) do
begin
strlen:=Length(strtemp);
mytemp:=pos(#9,strtemp);
If mytemp=0 Then
begin
mystr[counter]:=strtemp;
end
Else
begin
mystr[counter]:=Leftstr(strtemp,mytemp-1);
strtemp:=Rightstr(strtemp,strlen-mytemp);
counter:=counter+1;
end;
end;
end;
其中sk_ic.txt中的内容为:
“U999999 2100103 320200W00087268 XX交通卡有限公司 XX费 XX2费 XX3费”
不包括引号,各内容以Tab键相隔,如果内容中有中文,则无法分割,如果内容中只有数字或英文则可以

请问如何解决?
...全文
92 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞天揽月 2006-02-09
  • 打赏
  • 举报
回复

procedure TForm1.Button1Click(Sender: TObject);
var
ASource, ALien: TStringList;
i: Integer;
begin
ASource := TStringList.Create;
ALien := TStringList.Create;
Memo1.Lines.Clear;
ASource.LoadFromFile('C:\22.txt');
for i := 0 to ASource.Count - 1 do
begin
ALien.Clear;
ExtractStrings([' '], [],pchar(ASource.Strings[i]) , ALien);
Memo1.Lines.Add(ALien.Strings[0] + ' ' + ALien.Strings[5]);//Aline里的内容是你要的自己处理一下。
end;
end;
SiTwo 2006-02-09
  • 打赏
  • 举报
回复
使用WideString类型代替String类型,就行了
yrb 2006-02-09
  • 打赏
  • 举报
回复
我改了一下,能够分出来呀,你看看吧。

var
strlen,mytemp,counter:integer;
strtemp:string;
thefile:textfile;
mystr:array[0..13] of string;
begin
{
assignfile(thefile,'C:\sk_ic.txt');
reset(thefile);
read(thefile,strtemp);
closefile(thefile);
}
strtemp := 'U999999'#9'2100103'#9'320200W00087268'#9'XX交通卡有限公司'#9'XX费'#9'XX2费'#9'XX3费';
counter:=0;
while (length(strtemp)>0) or (pos(#9,strtemp)<>0) do
begin
strlen:=Length(strtemp);
mytemp:=pos(#9,strtemp);
If mytemp=0 Then
begin
mystr[counter]:=strtemp;
EXIT;
end
Else
begin
mystr[counter]:=Leftstr(strtemp,mytemp-1);
strtemp:=Rightstr(strtemp,strlen-mytemp);
counter:=counter+1;
end;
end;
end;

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧