首页 > 代码库 > delphi删除部分字符串(不区分大小写)

delphi删除部分字符串(不区分大小写)

type
TDelFlags = set of (dfDelBefore, dfDelAfter);

//删除ms字符串中endstr子字符串前面或后面的部分字符串

procedure Delstr(var ms: String; endstr: String; Flags: TDelFlags;
bself: Boolean = True);
var
l: Integer;
begin
l := length(endstr);
if pos(AnsiLowercase(endstr), AnsiLowercase(ms))=0 then
begin
exit;
end;

if dfDelBefore in Flags then
begin
if bself then
Delete(ms, 1, pos(AnsiLowercase(endstr), AnsiLowercase(ms)) + l - 1)
else
Delete(ms, 1, pos(AnsiLowercase(endstr), AnsiLowercase(ms)) - 1)
end
else
begin
if bself then
Delete(ms, pos(AnsiLowercase(endstr), AnsiLowercase(ms)), length(ms))
else
Delete(ms, pos(AnsiLowercase(endstr), AnsiLowercase(ms)) + l, length(ms))
end;
end;

 

 

//从src主字符串中截取两个字符串(str1和str2)之间的部分字符串

function GetCenterStr(src, str1, str2: string): string;

var
i, i2, i3: integer;
begin
i := 0;
i2 := 0;
i3 := 0;
Delstr(src, str1, [dfDelBefore]);
i := pos(AnsiLowercase(str1), AnsiLowercase(src));
i3 := pos(AnsiLowercase(str2), AnsiLowercase(src));
result := copy(src, i2 + 1, i3 - i2 - 1);
end;

 

delphi删除部分字符串(不区分大小写)