Jump to content
Sign in to follow this  
erezlevi

text file to unicode file

Recommended Posts

erezlevi

hi,

can anyone help we with converting a txt file from ANSI to UNICODE, what is the method on doing this ?

Share this post


Link to post
Share on other sites
PsaltyDS

hi,

can anyone help we with converting a txt file from ANSI to UNICODE, what is the method on doing this ?

It's very deep and complicated, but if you want to wade into it:

$sFileA = "C:\Temp\ANSI_Test.txt"
$sFileU = "C:\Temp\UTF_Test.txt"
$hFile = FileOpen($sFileU, 2 + 32) ; 2 = overwrite, 32 = UTF16 Little Endian 
FileWrite($hFile, FileRead($sFileA))
FileClose($hFile)
MsgBox(64, "Done", "Ta Da!!!")

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
dleigh

Related/similar problem (yes I know this is an old thread, but perhaps putting them together makes sense for the next guy/gal searching):

I have a file that is produced with the DOS "sort" command and it's in codepage 850. No FileOpen choice seems to read it correctly. Does AutoIt have a way to deal with this or does someone else know a way to deal with either getting DOS (Windows 7 in this case) to output it differently or to convert it afterwards?

Thank you!


Share this post


Link to post
Share on other sites
Jury

dleigh,

perhaps this will help:

or lok at this:

http://waterlan.home.xs4all.nl/dos2unix/dos2unix_beta.htm#conversion_modes

it has: Convert from DOS CP850 to Unix Latin-1

opensource: http://sourceforge.net/projects/dos2unix/

Edited by Jury

Share this post


Link to post
Share on other sites
jchd

Can you try this and report success/failure?

; read old DOS CP850 file
Local $hdl = FileOpen("Dos850.txt", 16)  ; read in binary mode
Local $binText850 = FileRead($hdl)
FileClose($hdl)
Local $text = __CodepageStructToString($binText850)
; from there, $text is a genuine copy of the Dos file, but now using native AutoIt Unicode encoding.
ConsoleWrite($text & @LF)

Func __CodepageStructToString($tText)
Local $aResult = DllCall("kernel32.dll", "int", "MultiByteToWideChar", "uint", 850, "dword", 0, "struct*", $tText, "int", -1, _
   "ptr", 0, "int", 0)
If @error Then Return SetError(1, @error, "") ; Dllcall error
Local $tWstr = DllStructCreate("wchar[" & $aResult[0] & "]")
$aResult = DllCall("Kernel32.dll", "int", "MultiByteToWideChar", "uint", 850, "dword", 0, "struct*", $tText, "int", -1, _
   "struct*", $tWstr, "int", $aResult[0])
If @error Then Return SetError(2, @error, "") ; Dllcall error
Return DllStructGetData($tWstr, 1)
EndFunc

Edit: I saw the previous post after sending mine. My ad hoc function is equivalent to the WinAPI call.

Edited by jchd

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.