1.取出一个字符串中'<' 和 '>'之间所包含的字符串, function Extractchar(Test:String):String; var p1,p2:integer; begin Result:=''; p1:=pos('<',Test); p2:=pos('>',Test); if (p2>p1) and (p1<>0) and (p2<>0) then Result:=Copy(Test,p1,p2-p1); end; 2.有'<'之前的字符串 p:=pos('<',Test); if p<>0 then Result:=Copy(Test,1,p);
用pos函数可以得到'<'和'>'的位置
如i:=pos('<',S);得到'<'在S中的第一次出现的位置
然后用copy函数复制出来
如copy(S,2,3);从第2 个起取3 个字符
如copy('abcdefg',2,3) 将返回'bcd'
function Extractchar(Test:String):String;
var
p1,p2:integer;
begin
Result:='';
p1:=pos('<',Test);
p2:=pos('>',Test);
if (p2>p1) and (p1<>0) and (p2<>0) then
Result:=Copy(Test,p1,p2-p1);
end;
2.有'<'之前的字符串
p:=pos('<',Test);
if p<>0 then
Result:=Copy(Test,1,p);