Delphi 中对Str字串进行处理后存入对应字段数据库中
每条字串之间用ASCII码的chr$(1)进行间隔,字串内的“字段1”、“字段2”、“字段3”字段之间用chr$(2)进行间隔;str='字段1chr(2)字段2chr(...
每条字串之间用ASCII码的chr$(1)进行间隔,字串内的“字段1”、“字段2”、“字段3”字段之间用chr$(2)进行间隔;
str='字段1 chr(2) 字段2 chr(2) 字段3 chr(1) 字段1 chr(2) 字段2 chr(2) 字段3 chr(1) 字段1 chr(2) 字段2 chr(2) 字段3'
delphi 语言中 如何把字串分隔开来,保存到数据库中 展开
str='字段1 chr(2) 字段2 chr(2) 字段3 chr(1) 字段1 chr(2) 字段2 chr(2) 字段3 chr(1) 字段1 chr(2) 字段2 chr(2) 字段3'
delphi 语言中 如何把字串分隔开来,保存到数据库中 展开
1个回答
展开全部
procedure SaveToDB(str:string);
var buf1,buf2:Array [0..1] of char;
buf:Array [0..8191] of char;
cpt1,cpt2:PChar;
C1,C2,C3:string;
step:integer;
begin
buf1[0]:=chr(1);
buf1[1]:=chr(0);
buf2[0]:=chr(2);
buf2[1]:=chr(0);
strplcopy(buf,str,8190);
strcat(buf,buf1);
cpt1:=buf;
s1:='';
s2:='';
s3:='';
step:=0;
while (true) do begin
if (Step<>2) then cpt2:=strpos(cpt1,buf2)
else cpt2:=strpos(cpt1,buf1);
if (cpt2=nil) then break;
cpt2^:=chr(0);
inc(step);
if (Step=1) then s1:=strpas(cpt1)
else if (Step=2) then s2:=strpas(cpt1)
else if (Step=3) then s3:=strpas(cpt1);
if (Step>=3) then begin
Step:=0;
//写数据库
Insert into table (c1,c2,c3) values (s1,s2,s3);
s1:='';
s2:='';
s3:='';
end;
cpt1:=cpt2+1;
end;
end;
var buf1,buf2:Array [0..1] of char;
buf:Array [0..8191] of char;
cpt1,cpt2:PChar;
C1,C2,C3:string;
step:integer;
begin
buf1[0]:=chr(1);
buf1[1]:=chr(0);
buf2[0]:=chr(2);
buf2[1]:=chr(0);
strplcopy(buf,str,8190);
strcat(buf,buf1);
cpt1:=buf;
s1:='';
s2:='';
s3:='';
step:=0;
while (true) do begin
if (Step<>2) then cpt2:=strpos(cpt1,buf2)
else cpt2:=strpos(cpt1,buf1);
if (cpt2=nil) then break;
cpt2^:=chr(0);
inc(step);
if (Step=1) then s1:=strpas(cpt1)
else if (Step=2) then s2:=strpas(cpt1)
else if (Step=3) then s3:=strpas(cpt1);
if (Step>=3) then begin
Step:=0;
//写数据库
Insert into table (c1,c2,c3) values (s1,s2,s3);
s1:='';
s2:='';
s3:='';
end;
cpt1:=cpt2+1;
end;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询