要求按照字符串中的指定分隔符将某一个字符串分解开来。
例如:a1,b1,c1,d34,e56
按照“,”来分解,结果应该是
a1
b1
c1
d34
e56
如果没有的话,这个怎样解决?

解决方案 »

  1.   

    有ExtractStrings(),返回一个Strings对象,你可以传一个Stringlist对象作为该函数的参数
    ExtractStrings([''],[','],str,stringlist),好象是这样,看看Extractstrings的参数帮助吧!如果我没记错的应该是这样的!
      

  2.   

    function ExtractStrings(Separators, WhiteSpace: TSysCharSet; Content: PChar; Strings: TStrings): Integer;DescriptionUse ExtractStrings to fill a string list with the substrings of the null-terminated string specified by Content.Separators is a set of characters that are used as delimiters, separating the substrings. Carriage returns, newline characters, and quote characters (single or double) are always treated as separators. Separators are ignored when inside a quoted string until the final end quote. (Note that quoted characters can appear in a quoted string if the quote character is doubled.)WhiteSpace is a set of characters to be ignored when parsing Content if they occur at the beginning of a string.Content is the null-terminated string to parse into substrings.Strings is a string list to which all substrings parsed from Content are added. The string list is not cleared by ExtractStrings, so any strings already in the string list are preserved.ExtractStrings returns the number of strings added to the Strings parameter.Note: ExtractStrings does not add empty strings to the list.
      

  3.   

    我知道有,Delphi 不知道,应该写起来也蛮简单的
      

  4.   

    //自己写个函数
    function SplitString(const source,ch:string):tstringlist;
    var
     temp:string;
     i:integer;
    begin
     result:=tstringlist.Create;
     temp:=source;
     i:=pos(ch,source);
     while i<>0 do
     begin
       result.Add(copy(temp,0,i-1));
       delete(temp,1,i);
       i:=pos(ch,temp);
     end;
     result.Add(temp);
    end;//调用
    procedure TForm1.Button1Click(Sender: TObject);
    var
     s : TStringlist;
     i : integer;
     b : string;
    begin
      s := splitstring('afsdfsdaaa,bbfdsfsdb,ccc',',');
      for i:=0 to s.Count-1 do
        b := b + s.Strings[i]+#13;
      showmessage(b);
      s.free;
    end;
      

  5.   

    对,得自己写函数,sean2000(地宽天高) 的方法不错
      

  6.   

    //TStringList有一个CommaText属性,刚好是用逗号分隔的字符串
    procedure TForm1.Button2Click(Sender: TObject);
    var
      i : Integer;
      SL : TStringList;
    begin
      SL := TStringList.Create;
      SL.CommaText := 'a,b,c';
      for i := 0 to SL.Count - 1 do
        Memo1.Lines.Add(SL[i]);
    end;
      

  7.   

    to:whitetiger8(白虎)
    对不起啊!我正好在结贴的时候你来了,所以没分哦。