16,748
社区成员
发帖
与我相关
我的任务
分享
//返回两个标志字符串之间的数字串
function SplitToNum(const sStr,BeginStr,EndStr:String):String;
var
i,iBg,iEd,iNo:Integer;
s:String;
begin
iBg:=Pos(BeginStr,sStr);
if iBg=0 then Exit;
iEd:=iBg+Pos(EndStr,Copy(sStr,iBg,Length(sStr)-iBg+1))-1;
if iEd=0 then iEd:=Length(sStr);
if iEd<=iBg then Exit;
s:=Copy(sStr,iBg,iEd-iBg+1);
iBg:=0;
iEd:=0;
for i := 1 to Length(s) do
begin
iNo:=Ord(s[i]);
if (iBg=0) And ((iNo=46) OR ((iNo>=48) AND (iNo<=57))) Then iBg:=i;
if (iBg>0) AND (iNo<>46) AND ((iNo<48) OR (iNo>57)) Then iEd:=i;
if (iBg>0) And (iEd>0) then Break;
end;
if (iBg>0) And (iEd>0) then
begin
s:=Copy(s,iBg,iEd-iBg);
Result:=s;
end
else
Result:='';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Items.Append(SplitToNum(memo1.Text,'rowcount=',' '));
ListBox1.Items.Append(SplitToNum(memo1.Text,'colcount=','>'));
ListBox1.Items.Append(SplitToNum(memo1.Text,'<d>','</d>'));
end;
var
gStr:string='<?xml version="1.0" encoding="UTF-8"?><error></error><page rowcount=''1'' colcount=''20''>'+
'<row><d>23122613000163</d><d>测试单位</d><d>1203651676</d><d>232332197405060612</d>'+
'<d>张三</d><d>1</d><d>1974-05-06</d><d>11</d><d>在职</d><d>62665679X</d><d>0.0</d>'+
'<d>0.0</d><d>0.0</d><d>0.0</d><d>0.0</d><d>1312.12</d><d>498.57</d><d></d><d></d><d></d></row></page>';
function SpliteStr(ABTag,AETag:string;var AStr:string):string;
var
iB,iE:Integer;
begin
iB:=Pos(ABTag,AStr);
iE:=Pos(AETag,AStr);
result:=copy(AStr,ib+length(ABTag),ie-ib-length(ABTag));
AStr:=Copy(AStr,iE+length(AETag),length(AStr));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s,s2,sRowCount,sColCount:string;
iB,iE:Integer;
begin
iB:=pos('<page ',gStr);
iE:=Pos('<row>',gStr);
if iB=0 then exit;
s:=Copy(gStr,iB+length('<page '),iE-iB);
iB:=Pos('=''',s);
iE:=Pos(''' ',s);
sRowCount:=Copy(s,iB+2,iE-iB-2);
s2:=Copy(s,iE,length(s));
iB:=Pos('=''',s2);
iE:=Pos('''>',s2);
sColCount:=Copy(s2,iB+2,iE-iB-2);
edit1.Text:=sRowCount;
edit2.Text:=sColCount;
s:=SpliteStr('<row>','</row>',gStr);
iE:=StrToInt(sColCount);
for iB:=1 to iE do
begin
memo1.Lines.Add(SpliteStr('<d>','</d>',s));
end;
end;