一个通用函数
function Compose(str: string;
fgf: string;
Num: Integer): string;
var
TempI: Integer;
ResultNum: Integer;
begin
ResultNum := 0;
if Num = 0 then
begin
while Truedo
begin
TempI := Pos(fgf, Str);
if TempI <> 0 then
begin
Inc(ResultNum);
Str := Copy(Str, TempI + Length(fgf), Length(Str));
end
else
Break;
end;
Result := IntToStr(ResultNum + 1);
end
else
begin
for TempI := 2 to Numdo
begin
ResultNum := Pos(fgf, str {Result});
if ResultNum = 0 then
str := ''
else
str := Copy(str, ResultNum + Length(fgf), Length(str));
end;
Result := Str;
ResultNum := Pos(fgf, str);
if ResultNum <> 0 then
Result := Copy(str, 1, ResultNum - 1);
end;
end;
对于你给出的
const testStr='//xxxx//yyyy//zzzz';
result0 := Compose(testStr,'//',0);{4};{返回用分隔符分成的断数}
result1 := Compose(testStr,'//',2);{xxxx};
result2 := Compose(testStr,'//',3);{yyyy};
result3 := Compose(testStr,'//',4);{zzzz};