;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       UtoA() and AtoU() 
;; 
;;ACTION         Converts Unicode to ASCII and ASCII to Unicode 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2008/10/05 
;; 
;;HISTORY        1.0  - 2008/10/05 - Initial Release 
;; 
;;SYNTAX         UtoA(string) or AtoU(string [, termflag]) 
;; 
;;PARAMETERS     string   - REQUIRED, an ASCII or Unicode string, as per function used 
;; 
;;               termflag - OPTIONAL, a boolean value determining if the termination char 
;;               (0000) should be added to the string (default is yes) 
;; 
;;REMARKS        Simple translation supporting only standard ASCII printable characters 
;; 
;;RETURNS        string, in ASCII or Unicode, as per function used 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K, WXP, W2K3, Vista 
;; 
;;EXAMPLES       $Ascii = UtoA($string) 
; 
; convert Unicode strings to ASCII 
Function UtoA($_String)
 
  ; return if string is empty 
  If Not $_String Exit 0 EndIf
 
  Dim $_S, $_I				; temp string, index pointer 
 
  ; get each character pair as hex and convert to ASCII character 
  For $_I = 1 to Len($_String) Step 4
    $_S = $_S + Chr(Val('&' + SubStr($_String, $_I, 2)))
  Next
 
  $UtoA = $_S
  Exit 0
 
EndFunction
 
; Convert ASCII strings to Unicode 
Function AtoU($_String, OPTIONAL $_TermFlag)
 
  Dim $_S, $_I				; temp string, index pointer 
 
  ; get each ASCII character and convert to hex words 
  For $_I = 1 to Len($_String)
    $_S = $_S + Right('00' + DecToHex(Asc(SubStr($_String, $_I, 1))), 2) + '00'
  Next
 
  $_TermFlag = IIf($_TermFlag = '', 1, Val($_TermFlag))
  If $_TermFlag
    $AtoU = LCase($_S) + '0000'
  EndIf
 
  Exit 0  
 
EndFunction