Jump to content
Sign in to follow this  

UTF-8 to Iso8859-1

Recommended Posts

Try something like this:

#include <WinAPI.au3>
#include <File.au3>

Global $path = @ScriptDir & '\UTF8'
Global $filesList_A = _FileListToArray($path, "*", 1) ; * oder *.txt

For $i = 1 To UBound($filesList_A) - 1
    $t = FileRead(FileOpen($path & '\' & $filesList_A[$i], 128))
    FileWrite($path & '\ANSI_' & $filesList_A[$i], _UTF8ToAnsi($t))

Func _UTF8ToAnsi($sUTF8)
    Local $iLen = StringLen($sUTF8)
    Local $stBuf = DllStructCreate("byte[" & $iLen * 2 & "];byte[2]")

    Local $aRet = DllCall("Kernel32.dll", "int", "MultiByteToWideChar", _
            "int", 65001, "int", 0, _
            "str", $sUTF8, "int", -1, _
            "ptr", DllStructGetPtr($stBuf), "int", $iLen * 2 + 2)

    Local $stOut = DllStructCreate("char[" & $iLen & "];char")

    $aRet = DllCall("kernel32.dll", "int", "WideCharToMultiByte", _
            "int", 0, "int", 0, _
            "ptr", DllStructGetPtr($stBuf), "int", -1, _
            "ptr", DllStructGetPtr($stOut), "int", $iLen + 1, _
            "int", 0, "int", 0)

    Return DllStructGetData($stOut, 1)
EndFunc   ;==>_UTF8ToAnsi

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post

Link to post
Share on other sites


Despite the possibility offered by the exerpt posted above, beware that _in general_ such conversion can't be done. I mean that UTF-8 is a representation for the whole Unicode set (more than 260000 codepoints and growing) while any ANSI (Latin1 or something else) codepage can only represent 256 characters, within them only the 128 "upper ASCII" differ.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...