function FindCharSet(const Data:string):integer;
const (*это в общем не нужно*)
CodePages: array[0..10] of string = ('utf-8','utf-16','windows-1251','koi8-r','iso-8859-1',
'iso-8859-15','windows-1252','iso-8859-2','iso-8859-3','iso-8859-4','iso-8859-5');
var Pos1,Pos2:integer; CharSet:string;
begin
Pos1:=PosEx('charset=',Data,1);
Pos2:=PosEx('>',Data,Pos1);
CharSet:=Copy(Data, Pos1,(Pos2-Pos1+1)); (*выделяем чарсет из страницы*)
if Pos1 > 0 then (*если чарсет есть тогда*)
begin
if True then (*если в чарсет нет указания на кодировку страницы, принудительно назначить 1251*)
begin
Result:=1251;
end
else (*когда номер страницы указан*)
begin
if PosEx('utf-8',CharSet,1) > 0 then Result:=65001;
if PosEx('utf-16',CharSet,1) > 0 then Result:=65001;
if PosEx('windows-1251',CharSet,1) > 0 then Result:=1251;
if PosEx('windows-1252',CharSet,1) > 0 then Result:=1252;
if PosEx('koi8-r',CharSet,1) > 0 then Result:=20866;
if PosEx('iso-8859-1',CharSet,1) > 0 then Result:=28591;
if PosEx('iso-8859-2',CharSet,1) > 0 then Result:=28592;
if PosEx('iso-8859-3',CharSet,1) > 0 then Result:=28593;
if PosEx('iso-8859-4',CharSet,1) > 0 then Result:=28594;
if PosEx('iso-8859-5',CharSet,1) > 0 then Result:=28595;
if PosEx('iso-8859-15',CharSet,1) > 0 then Result:=28605;
end;
end
else (когда чарсета нет, присваиваем принудительно)
begin
Result:=1251;
end;
end;