如何拆分字符串由SplitString或分隔符? [英] How to Split string by SplitString or delimiter?
本文介绍了如何拆分字符串由SplitString或分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在双方使用应用程序绑定。
在服务器端我有SQLite数据库
在客户端没有数据库;
客户端从服务器数据库获取数据。
与服务器代码我认为它是确定。客户端问题,我不能分裂!我在客户端写了代码。有人可以告诉我,我的错误在哪里?
如何拆分r3.Text:= AResource.Value.AsString; ?
服务器端代码
procedure TfServerPage.tAProfileResourceReceived(const Sender:TObject;
const AResource:TRemoteResource);
var
result:string;
r1,r2,r3:TstringList;
begin
如果AResource.Hint ='List'然后
begin
//ShowMessage(AResource.Value.AsString);
r1:= TStringList.Create;
r2:= TStringList.Create;
r3:= TStringList.Create;
rQuery.Open;
而不是rQuery.Eof do
begin
r1.add(rQuery.FieldByName('username')。AsString);
r2.add(rQuery.FieldByName('password')。AsString);
r3.add(rQuery.FieldByName('nickname')。AsString);
rQuery.Next;
结束
result:= r1.Text +#13 + r2.Text +#13 + r3.text;
tAProfile.SendString(tManager.RemoteProfiles.First,'List2',result);
end;
结束
客户端代码
procedure TfAuth.tAProfileResourceReceived(const Sender:TObject;
const AResource:TRemoteResource);
var i:integer;
r3,s1,s2,s3:TStringList;
begin
如果AResource.Hint ='List2'然后
begin
r3:= TStringList.Create;
r3.Text:= AResource.Value.AsString; //< -From Server
s1:= TStringList.Create;
s2:= TStringList.Create;
s3:= TStringList.Create;
s1.Text:= SplitString(r3.Text,#13)[0]; //拆分用户名
s2.Text:= SplitString(r3.Text,#13)[1]; // password
s3.Text:= SplitString(r3.Text,#13)[2]; // nickname
for i:= 0 to r3.Count do
begin
StringGrid1.Cells [0,i]:= s1 [i];
StringGrid1.Cells [1,i]:= s2 [i];
StringGrid1.Cells [2,i]:= s3 [i];
结束
结束
end;
解决方案
服务器端代码
result:= r1.Text +#0 + r2.Text +#0 + r3.text;
客户端代码
s1.Text:= SplitString(r3.Text,#0)[0];
s2.Text:= SplitString(r3.Text,#0)[1];
s3.Text:= SplitString(r3.Text,#0)[2];
I've Client And Server Apps. I'm using App tethering in both side. In a Server Side I've SQLite database In a Client Side There is no database; Client getting data from Server database. With Server Code I think it Is ok. Problem with Client ,I can not Splite!!! I wrote code on Client Side . Can someone tell me , where is my mistake??? How to Split r3.Text:=AResource.Value.AsString; ?
Server Side Code:
procedure TfServerPage.tAProfileResourceReceived(const Sender: TObject;
const AResource: TRemoteResource);
var
result:string;
r1,r2,r3:TstringList;
begin
if AResource.Hint='List' then
begin
//ShowMessage(AResource.Value.AsString);
r1:=TStringList.Create;
r2:=TStringList.Create;
r3:=TStringList.Create;
rQuery.Open;
while not rQuery.Eof do
begin
r1.add(rQuery.FieldByName('username').AsString);
r2.add(rQuery.FieldByName('password').AsString);
r3.add(rQuery.FieldByName('nickname').AsString);
rQuery.Next;
end;
result:=r1.Text+#13+r2.Text+#13+r3.text;
tAProfile.SendString(tManager.RemoteProfiles.First,'List2',result);
end;
end;
Client Side Code:
procedure TfAuth.tAProfileResourceReceived(const Sender: TObject;
const AResource: TRemoteResource);
var i:integer;
r3,s1,s2,s3:TStringList;
begin
if AResource.Hint='List2' then
begin
r3:=TStringList.Create;
r3.Text:=AResource.Value.AsString; // <-From Server
s1:=TStringList.Create;
s2:=TStringList.Create;
s3:=TStringList.Create;
s1.Text:=SplitString(r3.Text,#13)[0]; //Split username
s2.Text:=SplitString(r3.Text,#13)[1]; //password
s3.Text:=SplitString(r3.Text,#13)[2]; //nickname
for i := 0 to r3.Count do
begin
StringGrid1.Cells[0,i]:=s1[i];
StringGrid1.Cells[1,i]:=s2[i];
StringGrid1.Cells[2,i]:=s3[i];
end;
end;
end;
解决方案
Server Side Code:
result:=r1.Text+#0+r2.Text+#0+r3.text;
Client Side Code:
s1.Text:=SplitString(r3.Text,#0)[0];
s2.Text:=SplitString(r3.Text,#0)[1];
s3.Text:=SplitString(r3.Text,#0)[2];
这篇关于如何拆分字符串由SplitString或分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文