大家知道怎么做吗?
我的数据库有一个字段是这样的
1:如果字段的值是123456,789的话就要把
123456,789写到EDIT1中去
2:如果字段的值是123456,789,456,的话就要把
123456,789写到EDIT1中去.456写到EDIT2中去
3:如果字段的值是123456,789,456,123,461的话就要把
123456,789写到EDIT1中去.456,123写到EDIT2中去,
461写到EDIT3中去
除了用CASE语句还能怎么做
我写了一下很长的代码!我先要去判断有几个逗号在判断如果是1个就写到EDIT1.这样来写很长的代码的啊
我的数据库有一个字段是这样的
1:如果字段的值是123456,789的话就要把
123456,789写到EDIT1中去
2:如果字段的值是123456,789,456,的话就要把
123456,789写到EDIT1中去.456写到EDIT2中去
3:如果字段的值是123456,789,456,123,461的话就要把
123456,789写到EDIT1中去.456,123写到EDIT2中去,
461写到EDIT3中去
除了用CASE语句还能怎么做
我写了一下很长的代码!我先要去判断有几个逗号在判断如果是1个就写到EDIT1.这样来写很长的代码的啊
var
OutStringList:TStringList;
ListCount:Integer;
begin
ExtractStrings([','],[' '],PChar(YouNumStr),OutStringList);
case OutStringList.Count of
1,2: Edit1.Text:=ListToStr(OutStringList);
3,4: Edit1.Text:=ListToStr(OutStringList);
5,6: Edit1.Text:=ListToStr(OutStringList);
end;
end;
function ListToStr(AList:TStringList):String;
var
i:Integer;
begin
Result:=AList.Strings[0];
for i:=1 to AList.Count-1 do
Result:=Result+','+AList.Strings[i];
end;以上我没在Delphi中写,不过大体应该对的
如果第二个逗号前是等长的字符,可以直接取等长字符。
I: Integer;
begin
sL := TStringList.Create;
sL.Delimiter := ',';
sL.DelimitedText := edit4.Text;
for I:= 0 to sL.count-1 do
begin
case i of
0: edit1.Text := sL.Strings[0];
1: edit1.Text := sL.Strings[0] + ',' + sL.Strings[1];
2: edit2.Text := sL.Strings[2];
3: edit2.Text := sL.Strings[2] + ',' + sL.Strings[3];
4: edit3.Text := Sl.Strings[4];
end;
end;
sl.Free;
end;