字符串分割函数

来源:互联网 发布:java mysql怎么改密码 编辑:程序博客网 时间:2024/05/22 09:04
unit TMyTool;interfaceuses    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,    Dialogs, StdCtrls;type    TPMMS=Class(TObject)    private    public           constructor Create(); overload;           procedure SeparateTerms(s : string;Separator : char;Terms : TStringList);           function matching(id:integer):integer;    end;implementation     constructor TPMMS.Create();     begin         inherited Create;     end;     //分割字符串过程    procedure TPMMS.SeparateTerms(s : string;Separator : char;Terms : TStringList);    var         hs : string;         p : integer;   begin         Terms.Clear; // 清除字符串中的内容         if Length(s)=0 then    // 长度为0         Exit;         p:=Pos(Separator,s);         while P<>0 do         begin               if p<>1 then               begin                     hs:=Copy(s,1,p-1);    // 复制字符                     Terms.Add(hs);        // 添加到列表                     Delete(s,1,p);        // 删除字符和分割符                     p:=Pos(Separator,s); // 查找分割符               end               else               begin                     Delete(s,1,p);                     p:=Pos(Separator,s);               end;       end;       if Length(s)>0 then        Terms.Add(s);         // 添加剩下的条目end;
原创粉丝点击