大家知道怎么做吗?
我的数据库有一个字段是这样的
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.   

    function FillEdit(YouNumStr:stirng):Integer;
    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中写,不过大体应该对的
      

  2.   

    你就是要从第二个逗号处分开,如果用的是Delhi7可以试试PosEx,
    如果第二个逗号前是等长的字符,可以直接取等长字符。
      

  3.   

    var sL: TStringList;
      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;
      

  4.   

    flyany2000(flyany2000)  你的好象不可以哦!aiirii(ari-淘金坑) 这个楼主的建议不错但是还是有很长的代码!我还要分开看是0还是1.当是0就写123456.如果是1的话123456,789