如何通过多字符分隔符拆分字符串? [英] How to split string by a multi-character delimiter?
本文介绍了如何通过多字符分隔符拆分字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有 Delphi 函数可以通过多字符分隔符而不是单个字符来拆分字符串?
Is there a Delphi function to split string by a multi-character delimiter rather than a single character ?
例如,当我以这种方式使用该功能时:
For instance when I'd use that function this way:
SplitString('Whale<->Mammal<->Ocean', '<->')
我会得到这 3 个字符串的结果:
I would get a result of these 3 strings:
'Whale', 'Mammal', 'Ocean'
Delphi 有这个功能吗?
Is there such function in Delphi for this ?
推荐答案
还有另一个使用 TStringList 的非常简单的解决方案.更改换行符:
There is another quite simple solution using TStringList. Change the LineBreak:
procedure TForm208.Button1Click(Sender: TObject);
var
lst: TStringList;
begin
lst := TStringList.Create;
try
lst.LineBreak := '<->';
lst.Text := 'Whale<->Mammal<->Ocean';
Memo1.Lines := lst;
finally
lst.Free;
end;
end;
这篇关于如何通过多字符分隔符拆分字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文