一个效率不高但可行的办法
var
SepChar, UniqueChar: Char;
Patterns: TStrings;
SepPos, i: Integer;
Str: String;
begin
UniqueChar := '##'
//选择一个不会在文本中出现的字符串
SepChar := ','
//分隔符
Str := RichEdit1.Text;
Patterns := TStringList.Create;
SepPos := Pos(SepChar, Str);
while SepPos<>0 do
begin
Patterns.Add(Copy(Str, 1, SepPos-1));
Delete(Str, 1, SepPos);
SepPos := Pos(SepChar, Str);
end;
Patterns.Add(Str);
Str := RichEdit1.Text;
for i:=0 to Patterns.Count-1 do
begin
Str := StringReplace(Str, Patterns, UniqueChar, [rfIgnoreCase]);
Str := StringReplace(Str, Patterns, '', [rfReplaceAll, rfIgnoreCase]);
Str := StringReplace(Str, UniqueChar, Patterns, [rfReplaceAll, rfIgnoreCase]);
end;
Patterns.Free;
//加入这一句就可以去掉分隔符
//StringReplace(Str, SepChar, ' ', [rfReplaceAll, rfIgnoreCase])
RichEdit1.Text := Str;