delphi字符串替换分割函数delphi字符串替换分割函数

习题答案
考试通关必备网站

delphi字符串替换分割函数

//delphi分割字符串,
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;
delphi字符串列表(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;

未经允许不得转载:亿券答案网 » delphi字符串替换分割函数

我来解答

匿名发表
  • 验证码: