title: Delphi: Encoding Strings as Python do
body: <p>I want to encode strings as Python do.</p>
  
  <p>Python code is this:</p>
  
  <pre><code>def EncodeToUTF(inputstr):
    uns = inputstr.decode('iso-8859-2')
    utfs = uns.encode('utf-8')
    return utfs
  </code></pre>
  
  <p>This is very simple.</p>
  
  <p>But in Delphi I don't understand, how to encode, to force first the good character set (no matter, which computer we have).</p>
  
  <p>I tried this test code to see the convertion:</p>
  
  <pre><code>procedure TForm1.Button1Click(Sender: TObject);
  var
      w : WideString;
      buf : array[0..2048] of WideChar;
      i : integer;
      lc : Cardinal;
  begin
      lc := GetThreadLocale;
      Caption := IntToStr(lc);
      StringToWideChar(Edit1.Text, buf, SizeOF(buf));
      w := buf;
      lc := MakeLCID(
          MakeLangID( LANG_ENGLISH, SUBLANG_ENGLISH_US),
          0);
      Win32Check(SetThreadLocale(lc));
      Edit2.Text := WideCharToString(PWideChar(w));
      Caption := IntToStr(AnsiCompareText(Edit1.Text, Edit2.Text));
  end;
  </code></pre>
  
  <p>The input is: "árvíztűrő tükörfúrógép", the hungarian accent tester phrase.
  The local lc is 1038 (hun), the new lc is 1033.</p>
  
  <p>But this everytime makes 0 result (same strings), and the accents are same, I don't lost ŐŰ which is not in english lang.</p>
  
  <p>What I do wrong? How to I do same thing as Python do?</p>
  
  <p>Thanks for every help, link, etc:
     dd</p>