convert Windows-1251 Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
inseption86
Posts: 205
Joined: 19 Apr 2018, 00:24

convert Windows-1251

16 Apr 2024, 10:35

Good afternoon The result of the function is "%D0%A1%D0%BC%D0%B8%D1%80%D0%BD%D0%BE%D0%B2", but I need "%D1%EC%E8%F0%ED%EE%E2". How to convert Windows-1251?

Code: Select all


string := "Смирнов"
MsgBox, % EncodeDecodeURI(string)
ExitApp

EncodeDecodeURI(str, encode := true, component := true) {
   static Doc, JS
   if !Doc {
      Doc := ComObjCreate("htmlfile")
      Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
      JS := Doc.parentWindow
      ( Doc.documentMode < 9 && JS.execScript() )
   }
   Return JS[ (encode ? "en" : "de") . "codeURI" . (component ? "Component" : "") ](str)
}
inseption86
Posts: 205
Joined: 19 Apr 2018, 00:24

Re: convert Windows-1251  Topic is solved

16 Apr 2024, 11:03

Code: Select all

URIEncode(str, encoding := "CP1251")
{
   PrevFormat := A_FormatInteger
   SetFormat, IntegerFast, H
; кодируем стоку в указанную кодировку с помощью StrPut()
   VarSetCapacity(var, StrPut(str, encoding))
   StrPut(str, &var, encoding)
; последовательно перебирая символы, кодируем их в URL-формат   
   While code := NumGet(Var, A_Index - 1, "UChar")   ; пока code не равно 0, что означает конец строки
   {
      bool := (code > 0x7F || code < 0x30 || code = 0x3D)   ; отсеиваем символы, которые кодировать не нужно
      UrlStr .= bool ? "%" . SubStr("0" . SubStr(code, 3), -1) : Chr(code)
   }
   SetFormat, IntegerFast, % PrevFormat
   Return UrlStr
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: GEOVAN, Google [Bot], ShatterCoder, Spawnova and 398 guests