VB中有一个现成的Split函数,Delphi什么好办法?

解决方案 »

  1.   

    参考var
      list:TStringList;
    begin
      list.Delimiter := ':';
      list.DelimitedText := 'a:b:c:';
      ShowMessage(list.Text);
    end;
      

  2.   

    也可以用pos查找TAB的位置,然后copy
      

  3.   

    以tab键位分隔符分割字符串即可
      

  4.   

    给你一个函数:procedure SplitStringList(const source, ch: string; pList: TStrings);
    var
      pTmp: pchar;
      pCh: PChar;
      p: PChar;
      i,j: integer;
      s: string;
      iChLen: Integer;
    begin
      if (Length(Source)= 0) or not Assigned(pList) then
        exit;
      i:= 0;
      iChLen:= Length(ch);
      pTmp := pchar(source+ ch);
      pCh:= PChar(ch);  p:= StrPos(pTmp,pCh);
      if p<> nil then
      begin
        Inc(p,iChLen);
        i:= p- pTmp;
      end;
      pList.BeginUpdate;
      while i> 0 do
      begin
        j:= i- iChLen;
        SetLength(s,i- iChLen);
        if j> 0 then
        begin
          s:= StrLCopy(PChar(s),pTmp,i- iChLen);
          plist.Add(s);
        end;
        pTmp:= p;
        p:= StrPos(pTmp,pCh);
        if p<> nil then
        begin
          Inc(p,iChLen);
          i:= p- pTmp;
        end
        else if pTmp<> nil then   //保证最后一段字符也能被查找到
          i:= StrLen(pTmp)+ iChLen
        else
          i:=0;
      end;
      pList.EndUpdate;
    end;