比如我有这个个字符串
acceptstring:='[email protected],[email protected],[email protected],[email protected]'
我想以“,”号为分隔,把所有邮件地址放在一个数组里。代码应该怎么写。
acceptstring:='[email protected],[email protected],[email protected],[email protected]'
我想以“,”号为分隔,把所有邮件地址放在一个数组里。代码应该怎么写。
StringList: TStringList;
acceptstring: string;
begin
acceptstring:='[email protected],[email protected],[email protected],[email protected]';
StringList := TStringList.Create;
StringList.CommaText := acceptstring;
// 你的代码
Caption := StringList.Strings[0]; <---- //[email protected] StringList.Free
end;
{ 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;