AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Helper script to convert from one to another codepages

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 1249

PostPosted: Fri Mar 09, 2007 10:01 am    Post subject: Helper script to convert from one to another codepages Reply with quote

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
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 404
Location: Galil, Israel

PostPosted: Sat Apr 21, 2007 7:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1249

PostPosted: Sun Apr 22, 2007 8:02 am    Post subject: Reply with quote

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
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Sun Apr 22, 2007 8:31 am    Post subject: Reply with quote

Sean wrote:
I didn't know that I can use UTF-8 like this in AHK.
Neither me... Smile
Nor how this is better than Ansi2Unicode().
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group