S
sjhasp
Unregistered / Unconfirmed
GUEST, unregistred user!
我的表里面有三个字段,分别是:
name sex country
我现在有一字符串'sjh man cn '我想通过下面的程序把这字符串分开之后插入在一行记录内,即sjh对应name字段,man对应sex字段,cn对应country字段.但通过我自己的调试,下面程序的结果是,他把sjh分别插入到了三行记录里面,有点纳闷,请大家赐教!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, StdCtrls;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
Table1: TTable;
Button1: TButton;
Function GetSubStr(varaString:String; SepChar:String):String;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Const Space=' ';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
MyLine:string;
str:string;
i,j:Integer;
begin
MyLine:='sjh man cn ';
begin
for j:=1 to 3 do
begin
table1.append;
table1.fields[j-1].AsString:=GetSubStr(MyLine,Space);
table1.post;
end;
end;
end;
Function Tform1.GetSubStr(varaString:String; SepChar:String):String;
var
Mystr:String;
StrLen:Integer;
SepCharPos:Integer;
varastring1:string;
begin
StrLen:=Length(varaString);
SepCharPos:=Pos(SepChar,varaString); //计算分割符在子串中的位置
MyStr:=Copy(varaString,1,SepCharPos-1);//将分割符前所有字符放到mystr串中
Delete(varaString,1,SepCharPos); //除去分割符和分割符前的子串
GetSubStr:=MyStr;//返回一个字段
end;
end.
name sex country
我现在有一字符串'sjh man cn '我想通过下面的程序把这字符串分开之后插入在一行记录内,即sjh对应name字段,man对应sex字段,cn对应country字段.但通过我自己的调试,下面程序的结果是,他把sjh分别插入到了三行记录里面,有点纳闷,请大家赐教!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, StdCtrls;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
Table1: TTable;
Button1: TButton;
Function GetSubStr(varaString:String; SepChar:String):String;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Const Space=' ';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
MyLine:string;
str:string;
i,j:Integer;
begin
MyLine:='sjh man cn ';
begin
for j:=1 to 3 do
begin
table1.append;
table1.fields[j-1].AsString:=GetSubStr(MyLine,Space);
table1.post;
end;
end;
end;
Function Tform1.GetSubStr(varaString:String; SepChar:String):String;
var
Mystr:String;
StrLen:Integer;
SepCharPos:Integer;
varastring1:string;
begin
StrLen:=Length(varaString);
SepCharPos:=Pos(SepChar,varaString); //计算分割符在子串中的位置
MyStr:=Copy(varaString,1,SepCharPos-1);//将分割符前所有字符放到mystr串中
Delete(varaString,1,SepCharPos); //除去分割符和分割符前的子串
GetSubStr:=MyStr;//返回一个字段
end;
end.