//获得字符串中的子字符串,sourceStr为源字符串,Border为定界符,如',',' ',':'等,Index为子字符中的位置}
function GetStrItem(SourStr : string;Border : Char;Index : integer):string;
var
TempStr : string;
I : integer;
begin
TempStr := SourStr;
if Pos(Border,SourStr)=0 then Result := ''
else begin
try
for I := 1 to Index - 1 do begin
if Pos(Border,TempStr) = 0 then begin
Result := '';
Exit;
end;
Delete(TempStr,1,Pos(Border,TempStr));
end;
except
ShowMessage('Have not such Index!');
result := '';
Exit;
end;
if Pos(Border,TempStr)=0 then
Result := TempStr
else
Result := Copy(TempStr,1,Pos(Border,TempStr) - 1);
end;
end;
调用方法:getStrItem(SourceStr,intervalstr,position)
如
SS := a,12334,3,4
你想取第三个字符串'3',如下GetStrItem(SS,',',3)