REM UTF-8 To ANSI Converter
REM Converts the specified string from one encoding to another.
REM String length limit: 700 characters.
REM Don't forget to change "isk_str" before executing this script.
@echo off
setlocal enabledelayedexpansion  

rem The required string
set isk_str=

if exist ok.tmp del /q ok.tmp
set /a fl_osh_simv=0
 
set all_simv=" #$'()*+,-./0$123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¨¸
set simv_z="&#9576;Ð   &#9576;Ñ   &#9576;Ò   &#9576;Ó   &#9576;Ô   &#9576;Õ   &#9576;Ö   &#9576;×   &#9576;Ø   &#9576;Ù   &#9576;Ú   &#9576;Û   &#9576;Ü   &#9576;Ý   &#9576;Þ   &#9576;ß   &#9576;à   &#9576;á   &#9576;â   &#9576;ã   &#9576;ä   &#9576;å   &#9576;æ   &#9576;ç   &#9576;è   &#9576;é   &#9576;ê   &#9576;ë   &#9576;ì   &#9576;í   &#9576;î   &#9576;ï   &#9576;&#9617;   &#9576;&#9618;   &#9576;&#9619;   &#9576;&#9474;   &#9576;&#9508;   &#9576;&#9569;   &#9576;&#9570;   &#9576;&#9558;   &#9576;&#9557;   &#9576;&#9571;   &#9576;&#9553;   &#9576;&#9559;   &#9576;&#9565;   &#9576;&#9564;   &#9576;&#9563;   &#9576;&#9488;   &#9572;À   &#9572;Á   &#9572;Â   &#9572;Ã   &#9572;Ä   &#9572;Å   &#9572;Æ   &#9572;Ç   &#9572;È   &#9572;É   &#9572;Ê   &#9572;Ë   &#9572;Ì   &#9572;Í   &#9572;Î   &#9572;Ï   &#9576;Á   &#9572;Ñ"'

echo !all_simv! > test.tmp
 
set /A max_len_str=700
rem Calculating the string length (up to 700 characters)
:_vyasn_dl_str
set /A max_len_str=%max_len_str%-1
set new_str=!isk_str:~0,%max_len_str%!
if !new_str!==!isk_str! goto _vyasn_dl_str
set /A max_len_str=%max_len_str%-1
 
set /A max_len_dop=700
rem Calculating the search length
:_vyasn_dl_dop
set /A max_len_dop=%max_len_dop%-1
set new_str=!all_simv:~0,%max_len_dop%!
if !new_str!==!all_simv! goto _vyasn_dl_dop
 
set /A max_len_neizm=%max_len_dop%
rem Calculating the length of 'constant' string
:_vyasn_dl_neizm
set /A max_len_neizm=%max_len_neizm%-1
set new_str=!all_simv:~%max_len_neizm%,1!
if !new_str!==À goto _vyx_izm_dl
goto _vyasn_dl_neizm
:_vyx_izm_dl
set /A max_len_neizm=%max_len_neizm%
 
rem Removing commas
set new_str=!isk_str:~1,%max_len_str%!
 
rem Searching for characters...
set /A max_len_str=%max_len_str%-1
set str_pois=
for /l %%a in (0,1,%max_len_str%) do (
    set tek_simv=!new_str:~%%a,1!
    set /a fl_osh_simv=1
    for /l %%b in (0,1,%max_len_dop%) do (
        set simv_sravn=!all_simv:~%%b,1!
        if !tek_simv!==!simv_sravn! (
           set /a fl_osh_simv=0
           if %%b LSS %max_len_neizm% (
              set str_pois=!str_pois!!tek_simv!
           ) else (
              set /A polog_zam=%%b-%max_len_neizm%
              set /A polog_zam=5*!polog_zam!
              call :zam !polog_zam!
           )
        )  
    )
    if !fl_osh_simv!==1 (
       echo Character  !tek_simv! is not found
       exit /b)
)
 
rem Search itself
find /c "%str_pois%" test.tmp | find /c ": 0" > f.tmp
for /f %%i in (f.tmp) do if %%i==0 echo ok > ok.tmp
del /q f.tmp
del /q test.tmp
exit /b
 
:zam nom_simv
rem Changing the characters
if "!simv_z:~4,1!" NEQ " " (
   set str_pois=!str_pois!!simv_z:~%1,5!) else (
   if "!simv_z:~3,1!" NEQ " " (
      set str_pois=!str_pois!!simv_z:~%1,4!) else (
      if "!simv_z:~2,1!" NEQ " " (
         set str_pois=!str_pois!!simv_z:~%1,3!) else (
         if "!simv_z:~1,1!" NEQ " " (
            set str_pois=!str_pois!!simv_z:~%1,2!) else (
            set str_pois=!str_pois!!simv_z:~%1,1!
         )
      )
   )
)
exit /b
 