delphi 字符串列表(TStrings)中字符串替换函数代码 2009 年 11 月 04 日 星期三 09:532009 年 04 月 12 日 下午 03:47delphi 字符串
列表(TStrings)中字符串替换函 数代码 ━━━━━━━━━━━━━━━━━━━━━━━━━━ //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;