{ASourceStr:要分解的字符串,ABz:分解的标志} {例如 ASourceStr:='wwww##hao123##com';ABz:='##'} procedure GetStrings(var AStringList:TStringList;ASourceStr:string;ABz:String); var i:integer; Str:string; isTrue:Boolean; begin Str:= ASourceStr; isTrue:= True; try while isTrue do begin i:= 0; i:=pos(ABz,Trim(Str)); if i > 0 then begin AStringList.Add(Copy(Str,1,i-1)); Delete(Str,1,i+1); isTrue:= True; end else begin AStringList.Add(Str); isTrue:= False; end; end; except AStringList.Free; end; end; {调用如下} procedure TForm1.Button1Click(Sender: TObject); var Str:string; MyList:TStringList; i:Integer; txtFile:TextFile;begin MyList:=TStringList.Create; Str:= 'wwww##hao123##com'; try GetStrings(MyList,Str,'##'); for i:= 0 to MyList.Count -1 do begin mmo1.Lines.Add(MyList.Strings[i]); end; MyList.Free; except MyList.Free; end; end;
http://topic.csdn.net/t/20060414/10/4686187.html
{例如 ASourceStr:='wwww##hao123##com';ABz:='##'}
procedure GetStrings(var AStringList:TStringList;ASourceStr:string;ABz:String);
var
i:integer;
Str:string;
isTrue:Boolean;
begin
Str:= ASourceStr;
isTrue:= True;
try
while isTrue do
begin
i:= 0;
i:=pos(ABz,Trim(Str));
if i > 0 then
begin
AStringList.Add(Copy(Str,1,i-1));
Delete(Str,1,i+1);
isTrue:= True;
end
else
begin
AStringList.Add(Str);
isTrue:= False;
end;
end;
except
AStringList.Free;
end;
end;
{调用如下}
procedure TForm1.Button1Click(Sender: TObject);
var
Str:string;
MyList:TStringList;
i:Integer;
txtFile:TextFile;begin
MyList:=TStringList.Create;
Str:= 'wwww##hao123##com';
try
GetStrings(MyList,Str,'##');
for i:= 0 to MyList.Count -1 do
begin
mmo1.Lines.Add(MyList.Strings[i]);
end;
MyList.Free;
except
MyList.Free;
end;
end;