H
hying95
Unregistered / Unconfirmed
GUEST, unregistred user!
const
cnXM: Array [0..10] of string=('AB','CD','EF','ABT','ABW','ABH','CDT','CDW','CDH','EFT','EFW');
bArr: Array [0..10] of string=('12','42','36','01','02','03','04','02',
'06','03','06');
{
memo1中的字符列表如下
ABT+EFT+CDT+CD+CDH+ABW+AB
ABT+EFT+CDT+EF+CDH+ABW+CD
}
procedure TForm1.Button1Click(Sender: TObject);
var
i,J,N: integer;
s: string;
s1: string;
begin
For j:=0 to memo1.Lines.Count-1 do
begin
s1:=memo1.Lines.Strings[j];
for i := 0 to High(cnXM) dO
begin
s:=cnXM;
N:=pos(s,s1);
if (N>0) and (length(s)>2) then
s1:=StringReplace(s1,s,bArr,[rfReplaceAll]);
if (N>0) and (length(s)=2) then//为何下面这段程序不处理?
begin
if (Copy(S1,N+2,1)='+') or ((Copy(S1,N+2,1)='')) then
s1:=StringReplace(s1,s,bArr,[rfReplaceAll]);
end;
//如果在此再加一个循环,可以替换完.
end;
memo2.Lines.Add(s1);
end;
end;
{
程序执行后还有四个没有被替换结果如下
01+03+04+CD+06+02+AB
01+03+04+EF+06+02+CD
搞不懂.
}
cnXM: Array [0..10] of string=('AB','CD','EF','ABT','ABW','ABH','CDT','CDW','CDH','EFT','EFW');
bArr: Array [0..10] of string=('12','42','36','01','02','03','04','02',
'06','03','06');
{
memo1中的字符列表如下
ABT+EFT+CDT+CD+CDH+ABW+AB
ABT+EFT+CDT+EF+CDH+ABW+CD
}
procedure TForm1.Button1Click(Sender: TObject);
var
i,J,N: integer;
s: string;
s1: string;
begin
For j:=0 to memo1.Lines.Count-1 do
begin
s1:=memo1.Lines.Strings[j];
for i := 0 to High(cnXM) dO
begin
s:=cnXM;
N:=pos(s,s1);
if (N>0) and (length(s)>2) then
s1:=StringReplace(s1,s,bArr,[rfReplaceAll]);
if (N>0) and (length(s)=2) then//为何下面这段程序不处理?
begin
if (Copy(S1,N+2,1)='+') or ((Copy(S1,N+2,1)='')) then
s1:=StringReplace(s1,s,bArr,[rfReplaceAll]);
end;
//如果在此再加一个循环,可以替换完.
end;
memo2.Lines.Add(s1);
end;
end;
{
程序执行后还有四个没有被替换结果如下
01+03+04+CD+06+02+AB
01+03+04+EF+06+02+CD
搞不懂.
}