有一个字符串"001,002,003,004,005",
我想把他们分别列为5个字符串a='001',b='002',c='003',d='004',e='005'
请问高手如何解决

解决方案 »

  1.   

    var
     sl: TStringList;
    begin
      s := TStringList.Create;
      try
        s.Delimiter :=',';
        s.CommaText := 001,002,003,004,005';
      finally
        s.Free;
      end;
    end;这样以后,则
    s.String[0]=001, s.string[1]=002..........
      

  2.   

    i:integer;
    begin
    while pos(',',s)>0 do
    begin
    i:=pos(',',s);
    .......
    copy(s,0,i-1)附值给a,b,c,c;
    s:=stringreplace(s ,',','',[rfIgnoreCase]);
    s:=stringreplace(s ,copy(s,0,i-1),'',[rfIgnoreCase]);end;
      

  3.   

    参考一下这个函数吧首部 function AnsiStrScan(Str: PChar; Chr: Char): PChar; $[SysUtils.pas
    功能 返回在指针字符串Str搜索字符Chr第一个出现的地址
    说明 支持多字节字符系统;AnsiStrRScan('kingron.myetang.com', '.') = '.myetang.com'
    参考 function SysUtils.StrScan
    例子 Edit2.Text := AnsiStrScan(PChar(Edit1.Text), '.');
      

  4.   

    我的常用函数
    function Compose(str: string; Num: Integer; fgf: string = '|'): string;
    //例子
    //const testStr='001,002,003,004,005';
    //result0 := Compose(testStr,',',0);  '5';{返回用分隔符分成的断数}
    //result1 := Compose(testStr,',',1);  '001'
    //result2 := Compose(testStr,',',2);  '002';
    //result3 := Compose(testStr,',',3);  '003';
    var
      TempI: Integer;
      ResultNum: Integer;
    begin
      ResultNum := 0;
      if Num = 0 then
      begin
        while True do
        begin
          TempI := Pos(fgf, Str);
          if TempI <> 0 then
          begin
            Inc(ResultNum);
            Str := Copy(Str, TempI + Length(fgf), Length(Str));
          end
          else
            Break;
        end;
        Result := IntToStr(ResultNum + 1);
      end
      else
      begin
        for TempI := 2 to Num do
        begin
          ResultNum := Pos(fgf, str {Result});
          if ResultNum = 0 then
            str := ''
          else
            str := Copy(str, ResultNum + Length(fgf), Length(str));
        end;
        Result := Str;
        ResultNum := Pos(fgf, str);
        if ResultNum <> 0 then
          Result := Copy(str, 1, ResultNum - 1);
      end;
    end;