var sl: TStringList; begin s := TStringList.Create; try s.Delimiter :=','; s.CommaText := 001,002,003,004,005'; finally s.Free; end; end;这样以后,则 s.String[0]=001, s.string[1]=002..........
i:integer; begin while pos(',',s)>0 do begin i:=pos(',',s); ....... copy(s,0,i-1)附值给a,b,c,c; s:=stringreplace(s ,',','',[rfIgnoreCase]); s:=stringreplace(s ,copy(s,0,i-1),'',[rfIgnoreCase]);end;
我的常用函数 function Compose(str: string; Num: Integer; fgf: string = '|'): string; //例子 //const testStr='001,002,003,004,005'; //result0 := Compose(testStr,',',0); '5';{返回用分隔符分成的断数} //result1 := Compose(testStr,',',1); '001' //result2 := Compose(testStr,',',2); '002'; //result3 := Compose(testStr,',',3); '003'; var TempI: Integer; ResultNum: Integer; begin ResultNum := 0; if Num = 0 then begin while True do 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 Num do 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;
sl: TStringList;
begin
s := TStringList.Create;
try
s.Delimiter :=',';
s.CommaText := 001,002,003,004,005';
finally
s.Free;
end;
end;这样以后,则
s.String[0]=001, s.string[1]=002..........
begin
while pos(',',s)>0 do
begin
i:=pos(',',s);
.......
copy(s,0,i-1)附值给a,b,c,c;
s:=stringreplace(s ,',','',[rfIgnoreCase]);
s:=stringreplace(s ,copy(s,0,i-1),'',[rfIgnoreCase]);end;
功能 返回在指针字符串Str搜索字符Chr第一个出现的地址
说明 支持多字节字符系统;AnsiStrRScan('kingron.myetang.com', '.') = '.myetang.com'
参考 function SysUtils.StrScan
例子 Edit2.Text := AnsiStrScan(PChar(Edit1.Text), '.');
function Compose(str: string; Num: Integer; fgf: string = '|'): string;
//例子
//const testStr='001,002,003,004,005';
//result0 := Compose(testStr,',',0); '5';{返回用分隔符分成的断数}
//result1 := Compose(testStr,',',1); '001'
//result2 := Compose(testStr,',',2); '002';
//result3 := Compose(testStr,',',3); '003';
var
TempI: Integer;
ResultNum: Integer;
begin
ResultNum := 0;
if Num = 0 then
begin
while True do
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 Num do
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;