delphi取某两个字符间的字符

来源:百度知道 编辑:UC知道 时间:2024/06/16 00:35:24
var
a:string;
begin
a:='<id>437FE4532921554</id><sex>sex</sex>'
......//不会了...
end;
我想取得<id>和</id>之间的字符串怎么做阿.
帮帮我拉. 那个<id></id>之间的是变量.. 怎么做阿.
帮帮我吧 .....

例子程序如下:

{$apptype console}
program exp;
var a:string; i,j:integer;
begin
a:='<id>437FE4532921554</id><sex>sex</sex>';
i:=pos('<id>',a);
j:=pos('</id>',a);
if (i>0) and (j>0) and (j>i) then writeln(copy(a,i+4,j-i-4))
else writeln('Not found');
end.

DELPHI下调试用过,运行过程如下:
E:\ygb>dcc32 a.dpr
Borland Delphi Version 15.0
Copyright (c) 1983,2002 Borland Software Corporation
a.dpr(10)
11 lines, 0.06 seconds, 10892 bytes code, 1805 bytes data.

E:\ygb>a.exe
437FE4532921554