我想实现对Memo1中的每一个字符与一硬盘上的文本文件中的内容比较,文本文件的格式是:中China //第1行
国country //第2行
人people //第3行
...
...当Memo1中的某一字符与文本文件中的字符相同时,将Memo1中的该字符替换成与之相对应的英文.如Memo1中的"国家",经处理后,会变成"country家"
如Memo1中的"国 人",经处理后,会变成"country people"我一次只能给100分,解决后再给分100分.
国country //第2行
人people //第3行
...
...当Memo1中的某一字符与文本文件中的字符相同时,将Memo1中的该字符替换成与之相对应的英文.如Memo1中的"国家",经处理后,会变成"country家"
如Memo1中的"国 人",经处理后,会变成"country people"我一次只能给100分,解决后再给分100分.
hangyu='中国人'
englist='china country people'
sFl: TStringList;
i, j, k: integer; s: string;
begin
sFl := TStringList.Create;
sFl.LoadFromFile('d:\a.txt');
if sFl.Count = -1 then
begin
sFl.Free;
exit;
end;
k := sFl.Count;
setLength(sChi,k);
setLength(sEng,k);
for I:= 0 to k - 1 do
begin
sChi[i] := Copy(Sfl.Strings[i], 1, 2);
sEng[i] := Copy(Sfl.Strings[i], 3, 100);
showmessage(sChi[i] + ' - ' + sEng[i]);
end;
sFl.Free; for i:= 0 to memo1.Lines.Count - 1 do
begin
s := Memo1.Lines.Strings[i];
for j:=0 to k-1 do
begin
s := StringReplace(S, sChi[j], sEng[j], [rfReplaceAll]);
end;
Memo1.Lines.Strings[i] := s;
end;
end;
AList:TStringList;
i:Integer;
Chinese,English:string;
begin
AList:=TStringList.Create;
AList.LoadFromFile(filename);
for i:=0 to AList.Count-1 do
begin
Chinese:=Copy(AList.Strings[i],1,2);
English:=Copy(AList.Strings[i],3,MaxInt);
Memo1.Text:=StringReplace(Memo1.Text,Chinese,English,[rfReplaceAll]);
end;
AList.Free;
end;