Home > Back-end >  Delphi on how to capture the values in the string of big head
Delphi on how to capture the values in the string of big head

Time:09-18

The string is as follows:
<? The XML version="1.0" encoding="utf-8"?>


23122613000163 & lt;/d>
The test unit & lt;/d>
1203651676 & lt;/d>
232332197405060612 & lt;/d>
Zhang SAN & lt;/d>
1
The 1974-05-06 & lt;/d>
11 & lt;/d>
On-the-job & lt;/d>
62665679 x & lt;/d>
0.0 & lt;/d>
0.0 & lt;/d>
0.0 & lt;/d>
0.0 & lt;/d>
0.0 & lt;/d>
1312.12 & lt;/d>
498.57 & lt;/d>





Problem a, how can you remove & lt; Page rowcount='1' colcount='20' & gt; 20 in the rowcount=1 of 1, colcount
Question 2, how can cycle & lt; Row> All & lt; D> Value of each loop out
Thank you expert guidance

CodePudding user response:

1, use the XMLDocument to parse it,
2, there is something wrong with your XML structure, hierarchy, XML can have only one Root, you there are multiple Root (Root),

CodePudding user response:

The standard XML,

CodePudding user response:

 
Var
GStr: string='& lt; ? The XML version="1.0" encoding="utf-8"?> '& lt; Row> 23122613000163 & lt;/d> The test unit & lt;/d> 1203651676 & lt;/d> 232332197405060612 & lt;/d> + '
'& lt; D> Zhang SAN & lt;/d> 1 The 1974-05-06 & lt;/d> 11 & lt;/d> On-the-job & lt;/d> 62665679 x & lt;/d> 0.0 & lt;/d> + '
'& lt; D> 0.0 & lt;/d> 0.0 & lt;/d> 0.0 & lt;/d> 0.0 & lt;/d> 1312.12 & lt;/d> 498.57 & lt;/d>
';

The function SpliteStr (ABTag, AETag: string; Var AStr: string) : string;
Var
The iB, iE: Integer;
The 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;
The iB, iE: Integer;
The begin
IB:=pos (' & lt; Page ', gStr);
IE:=Pos (' & lt; Row> ', gStr);
If the iB=0 then the exit;
S:=Copy (gStr, iB + length (' & lt; 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 (" '& gt; ', s2);
SColCount:=Copy (s2, iB + 2, iE - iB - 2);

Edit1. Text:=sRowCount;
Edit2. Text:=sColCount;
S:=SpliteStr (' & lt; Row> ',' ', gStr);
IE:=StrToInt (sColCount);
For the iB:=1 to do iE
The begin
Memo1. Lines. The Add (SpliteStr (' & lt; D> ',' 's));
end;
end;

CodePudding user response:

Delete & lt; Error> , is the standard XML format, the structure is as follows:


<? The XML version="1.0"?>

23122613000163 & lt;/d>
The test unit & lt;/d>
1203651676 & lt;/d>
232332197405060612 & lt;/d>
Zhang SAN & lt;/d>
1
The 1974-05-06 & lt;/d>
11 & lt;/d>
On-the-job & lt;/d>
62665679 x & lt;/d>
0.0 & lt;/d>
0.0 & lt;/d>
0.0 & lt;/d>
0.0 & lt;/d>
0.0 & lt;/d>
1312.12 & lt;/d>
498.57 & lt;/d>


CodePudding user response:

//returns a string between two symbols of digital string
The function SplitToNum (const sStr, BeginStr EndStr: String) : String;
Var
I, iBg, iEd, iNo: Integer;
S: a String;
The begin
IBg:=Pos (BeginStr, sStr);
If iBg=0 then the 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:=0 to Length (s) do
The begin
INo:=word (s/I + 1);
If (iBg=0) And ((iNo=46) OR ((iNo>=48) AND (iNo<=57))) Then iBg:=I + 1;
If (iBg> 0) AND (iNo<> 46) AND ((iNo<48) OR (iNo> 57)) Then iEd:=I + 1;
If (iBg> 0) And (iEd> 0) then Break;
end;
If (iBg> 0) And (iEd> 0) then
The begin
S:=Copy (s, iBg, iEd - iBg);
Result:=s;
End
The else
Result:=';
end;

Procedure TForm1. Button1Click (Sender: TObject);
The begin
ListBox1. Items. Append (SplitToNum (memo1. Text, 'the rowcount=', '));
ListBox1. Items. Append (SplitToNum (memo1. Text, 'colcount=', '& gt; '));
ListBox1. Items. Append (SplitToNum (memo1. Text, '& lt; D> ',' '));
end;nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related