 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Sean
Joined: 12 Feb 2007 Posts: 1249
|
Posted: Fri Mar 09, 2007 10:01 am Post subject: Helper script to convert from one to another codepages |
|
|
This is a helper script to convert between codepages.
ANSI <-> OEM
ANSI <-> UTF8
| Code: | /*
CP_ACP = 0
CP_OEMCP = 1
CP_MACCP = 2
CP_UTF7 = 65000
CP_UTF8 = 65001
*/
Ansi2Oem(sString)
{
Ansi2Unicode(sString, wString, 0)
Unicode2Ansi(wString, zString, 1)
Return zString
}
Oem2Ansi(zString)
{
Ansi2Unicode(zString, wString, 1)
Unicode2Ansi(wString, sString, 0)
Return sString
}
Ansi2UTF8(sString)
{
Ansi2Unicode(sString, wString, 0)
Unicode2Ansi(wString, zString, 65001)
Return zString
}
UTF82Ansi(zString)
{
Ansi2Unicode(zString, wString, 65001)
Unicode2Ansi(wString, sString, 0)
Return sString
}
Ansi2Unicode(ByRef sString, ByRef wString, CP = 0)
{
nSize := DllCall("MultiByteToWideChar"
, "Uint", CP
, "Uint", 0
, "Uint", &sString
, "int", -1
, "Uint", 0
, "int", 0)
VarSetCapacity(wString, nSize * 2)
DllCall("MultiByteToWideChar"
, "Uint", CP
, "Uint", 0
, "Uint", &sString
, "int", -1
, "Uint", &wString
, "int", nSize)
}
Unicode2Ansi(ByRef wString, ByRef sString, CP = 0)
{
nSize := DllCall("WideCharToMultiByte"
, "Uint", CP
, "Uint", 0
, "Uint", &wString
, "int", -1
, "Uint", 0
, "int", 0
, "Uint", 0
, "Uint", 0)
VarSetCapacity(sString, nSize)
DllCall("WideCharToMultiByte"
, "Uint", CP
, "Uint", 0
, "Uint", &wString
, "int", -1
, "str", sString
, "int", nSize
, "Uint", 0
, "Uint", 0)
}
|
|
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 404 Location: Galil, Israel
|
Posted: Sat Apr 21, 2007 7:23 pm Post subject: |
|
|
Thanks. Was very helpful.
here is an example of how I've used it, to cleanly send Word unicode ...
| Quote: | text := Ansi2UTF8(text)
Transform, Clipboard, Unicode, %text% |
_________________ Joyce Jamce |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1249
|
Posted: Sun Apr 22, 2007 8:02 am Post subject: |
|
|
| Joy2DWorld wrote: | | Thanks. Was very helpful. |
Thanks.
| Quote: | text := Ansi2UTF8(text)
Transform, Clipboard, Unicode, %text% |
I didn't know that I can use UTF-8 like this in AHK. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Sun Apr 22, 2007 8:31 am Post subject: |
|
|
| Sean wrote: | | I didn't know that I can use UTF-8 like this in AHK. | Neither me...
Nor how this is better than Ansi2Unicode(). _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|