function ReplaceStr(const S, FindStr, RepStr: string; UpLow: Boolean): string;
var
 PosList   : TList;
 DestIndex  : Integer;
 i,Count   : Integer;
 p, e, ps, pe: PChar;
 zs, zo: String;
begin
 zs := S; zo := FindStr;
 if UpLow then //大・小文字を区別しない
 begin
   zs := AnsiLowerCase(zs);
   zo := AnsiLowerCase(zo);
 end;
 Result := S;
 if FindStr = '' then Exit;
 PosList := TList.Create;
 try
  p := PChar(zs);
  e := p + Length(S);
  ps := PChar(zo);
  pe := ps + Length(FindStr);
  while p < e do
  begin //ソース文字列のどの位置に置換すべき文字列があるかをリストに保持
   p := AnsiStrPosEx(p, e, ps, pe);
   if p = nil then Break;
   PosList.Add(p-PChar(zs)+PChar(S));
   Inc(p, Length(FindStr));
  end;
  if PosList.Count = 0 then Exit;