delphi字符串列表(TStrings)中字符串替换函数代码

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:47   1815   0
//TStrings中的字符串替换,在win xp, delphi 7下测试通过
//参数和StringReplace的参数相同,除了第一个参数为TStrings和返回值,第一个参数即作为输入参数,也作为输出参数
procedure StringsReplace(var S : TStrings; OldPattern, NewPattern: string; Flags: TReplaceFlags);
var i : integer;
tmpstr : string;
begin
for i := 0 to S.Count -1 do
begin
tmpstr := S[i];
s[i] := StringReplace(tmpstr, OldPattern, NewPattern, Flags);
end;
end;

//分割字符串,从网上搜索的也很好使
function SplitString(Source, Deli: string ): TStringList;stdcall;
var
EndOfCurrentString: byte;
StringList:TStringList;
begin
StringList:=TStringList.Create;
while Pos(Deli, Source)>0 do
begin
EndOfCurrentString := Pos(Deli, Source);
StringList.add(Copy(Source, 1, EndOfCurrentString - 1));
Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) - EndOfCurrentString);
end;
Result := StringList;
StringList.Add(source);
end;
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP