Jump to content



Photo

text file to unicode file


  • Please log in to reply
4 replies to this topic

#1 erezlevi

erezlevi

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 436 posts

Posted 10 January 2008 - 03:39 PM

hi,

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







#2 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 10 January 2008 - 06:53 PM

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

#3 dleigh

dleigh

    Seeker

  • Active Members
  • 21 posts

Posted 15 April 2012 - 02:37 PM

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!
Posted Image

#4 Jury

Jury

    Wayfarer

  • Active Members
  • Pip
  • 75 posts

Posted 15 April 2012 - 04:42 PM

dleigh,

perhaps this will help:

http://www.autoitscript.com/forum/topic/...string-from-codepage-437-or-85

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, 15 April 2012 - 05:09 PM.


#5 jchd

jchd

    Whatever your capacity, resistance is futile.

  • MVPs
  • 3,256 posts

Posted 15 April 2012 - 05:01 PM

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, 15 April 2012 - 05:05 PM.

SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQL tutorial (covers generic SQL, but most of it apply to SQLite as well)An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious workPCRE v8.32 regexp pattern documentation. AutoIt uses a slightly older version so that more advanced features are not all available.RegExp tutorial: enough to get started




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users