var YourText:TStringlist; SS:String; i:integer YourText:=TStringlist.Creat(); YourText.delimiter:=','; YourText.delimitedText:='1,2,3,4,5,45,50' SS:=''; for i:=0 to YourText.Count-1 do SS:=SS+YourText[i]; FieldByName('你的字段').AsString:=SS; // SS的值是 '123454550'
呵呵,忘了,上面最好在最后加一句
YourText.Free;
var ...........//省略了 S := '1,2,3,4,5,45,50'; begin while pos(',',s)> 0 do begin xxx := copy(s,pos(',',s)+1,length(s)-pos(',',s)); delete(s,pos(',',s)+1,length(s)-pos(',',s)); s1 := s ;//这里没有去掉',' memo1.Lines.Add(s1); s := xxx; end;
function GetString(const str,ctlstr : string): Tstrings; var strl : Tstrings; i : integer; s : string; substr : string; begin s := str; if length(trim(s)) = 0 then exit; strl := Tstringlist.Create; i := pos(ctlstr,S); while i > 0 do begin substr := copy(s,1,i-1); strl.Add(substr); Delete(S,1,i); i := pos(ctlstr,s); end; result := strl; end;procedure TForm1.Button1Click(Sender: TObject); var str : string; i : integer; strl : Tstrings; begin str := '1234#4567#3456#2345#'; strl := Tstringlist.Create; Strl := Getstring(str,'#'); for i := 0 to strl.Count - 1 do begin showmessage(strl.Strings[i]); end;end;
procedure StrtoStrList(Value: string; var Target: TStrings); var iStart: integer; iEnd: integer; begin iStart:= 1; repeat iEnd:= PosEx(',', Value, iStart); if iEnd = 0 then begin Target.Add(Copy(Value, iStart, Length(Value))); break; end; Target.Add(Copy(Value, iStart, iEnd - iStart)); iStart:= iEnd + 1; until istart <=0; end; 结果会把Value按','分隔放入Target
哈哈,照猫画虎,学楼上的。
YourText:TStringlist;
SS:String;
i:integer YourText:=TStringlist.Creat();
YourText.delimiter:=',';
YourText.delimitedText:='1,2,3,4,5,45,50'
SS:='';
for i:=0 to YourText.Count-1 do
SS:=SS+YourText[i];
FieldByName('你的字段').AsString:=SS;
// SS的值是 '123454550'
YourText.Free;
...........//省略了
S := '1,2,3,4,5,45,50';
begin
while pos(',',s)> 0 do
begin
xxx := copy(s,pos(',',s)+1,length(s)-pos(',',s));
delete(s,pos(',',s)+1,length(s)-pos(',',s));
s1 := s ;//这里没有去掉','
memo1.Lines.Add(s1);
s := xxx;
end;
function GetString(const str,ctlstr : string): Tstrings;
var
strl : Tstrings;
i : integer;
s : string;
substr : string;
begin
s := str;
if length(trim(s)) = 0 then
exit;
strl := Tstringlist.Create;
i := pos(ctlstr,S);
while i > 0 do
begin
substr := copy(s,1,i-1);
strl.Add(substr);
Delete(S,1,i);
i := pos(ctlstr,s);
end;
result := strl;
end;procedure TForm1.Button1Click(Sender: TObject);
var
str : string;
i : integer;
strl : Tstrings;
begin
str := '1234#4567#3456#2345#';
strl := Tstringlist.Create;
Strl := Getstring(str,'#');
for i := 0 to strl.Count - 1 do
begin
showmessage(strl.Strings[i]);
end;end;
var
iStart: integer;
iEnd: integer;
begin
iStart:= 1;
repeat
iEnd:= PosEx(',', Value, iStart);
if iEnd = 0 then
begin
Target.Add(Copy(Value, iStart, Length(Value)));
break;
end;
Target.Add(Copy(Value, iStart, iEnd - iStart));
iStart:= iEnd + 1;
until istart <=0;
end;
结果会把Value按','分隔放入Target