listbox item内有如下的内容:AAA21A->3333->EEEED->EA233
请问如何分别得到:AAA21A,3333,EEEED,EA233 
就是得到以'->'分开的每一段字符 

解决方案 »

  1.   

    procedure SeparateTerms(s : string;Separator : char;Terms : TStringList);
    { This browses a string and divide it into terms whenever the given
      separator is found. The separators will be removed }
      var
      hs : string;
      p : integer;begin
      Terms.Clear; // First remove all remaining terms
      if Length(s)=0 then   // Nothin' to separate
        Exit;
      p:=Pos(Separator,s);
      while P<>0 do
      begin
        hs:=Copy(s,1,p-1);   // Copy term
        Terms.Add(hs);       // Add to list
        Delete(s,1,p);       // Remove term and separator
        p:=Pos(Separator,s); // Search next separator
      end;
      if Length(s)>0 then
        Terms.Add(s);        // Add remaining term
    end;==========
    = 用  法 
    ==========var
    Terms : TStringList;
    i : integer;const
    TestStr = '1st term;2nd term;3rd term';begin
      Terms:=TStringList.Create;
      SeparateTerms(TestStr,';',Terms);
      for i:=0 to terms.Count-1 do
        ShowMessage(Terms.Strings[i]);
      Terms.Free;
    end;
      

  2.   

    var
       StringList:TStringList;
       i,j:Integer;
    begin
       StringList:=TStringList.Create;
       for j:=0 to ListBox1.Items.Count do
       begin
          StringList.Clear;
          StringList:=StringReplace(ListBox1.Items.string[j],'->',#13#10,[rfReplaceAll]);
          for i:=0 to StringList.Count-1 do
          begin
             ShowMessage(StringList.Strings[i]);//就这样子取得了
          end;
       end;
       StringList.Free;
    end;
      

  3.   

    begin
      Terms:=TStringList.Create;
      SeparateTerms(TestStr,'->',Terms);
      for i:=0 to terms.Count-1 do
        ShowMessage(Terms.Strings[i]);
      Terms.Free;
    end;
      

  4.   

    to 僵哥
    你好,可能我没有表达清楚:我的意思是这样的:listbox1内有以下内容:
    aaa3->ddd9->bb
    eeee->444->a555
    abe3->4ee->accc
    ............
    就是说listbox内的内容是如上这样格式的,我想实现的是
    for i=0 to listbox1.Items.Count-1 do
    当i=0时
    str1:=eeee
    str2:=ddd9
    str3:=bb
    当i=1时
    str1:=aaa3
    str2:=444
    str3:=a555
    以此类推
    对每一行的内容分别取出字符赋给其它参数如:
      

  5.   

    to 僵哥不好意思,上面有两行错了,是这样的:
    listbox1内有以下内容:
    aaa3->ddd9->bb
    eeee->444->a555
    abe3->4ee->accc
    ............
    就是说listbox内的内容是如上这样格式的,我想实现的是
    for i=0 to listbox1.Items.Count-1 do
    当i=0时
    str1:=aaa3
    str2:=ddd9
    str3:=bb
    当i=1时
    str1:=eeee
    str2:=444
    str3:=a555
    以此类推
    对每一行的内容分别取出字符赋给其它参数如:
      

  6.   

    其实不用这么麻烦,使用StrUtils.ReplaceStr(ListBox.Items.Text, '->', ',')就可以了。