function ReplaceStr(const Str: string): string;
var
  i: integer;
begin
  Result := '';
  for i := 0 to Length(Str) - 1 do
    begin
      if Str[i] = Chr(13) then
        Result := Result + '<Br>'
      else if Str[i] = '<' then
        Result := Result + '&lt;'
      else if Str[i] = ' ' then
        Result := Result + '&nbsp;'
      else if Str[i] = Chr(34) then
        Result := Result + '&quot;'
      else if Str[i] = Chr(39) then
        Result := Result + '&#39;'
      else
        Result := Result + Str[i];
    end;
end;