Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Reading € from a file


  • Please log in to reply
7 replies to this topic
TheIrishThug
  • Members
  • 419 posts
  • Last active: Jan 18 2012 02:51 PM
  • Joined: 19 Mar 2006
I'm getting varrying results when trying to read the euro symbol from text files. Conviniently it happens to not be reading correctly from the webpage that I am download and intend to read from. But it does work when I am reading from a new text file I create myself. I think it is appearing in variables as the string €.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Maybe the text file was saved in UTF-8 encoded Unicode. Try copying the text to Notepad and save ANSI encoded (File / Save as...).

TheIrishThug
  • Members
  • 419 posts
  • Last active: Jan 18 2012 02:51 PM
  • Joined: 19 Mar 2006
Damn, you ar good. Now the question is, is there a way to automate that conversion so I can build it into the script?

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
You don't have to convert the files, but convert the text when used. The simplest solution was to assign the read-in text to Clipboard and then use the Transform command, "Transform, Clipboard, Unicode, %MyUTF_String%", what places Unicode text onto the clipboard. Assigning it to an AHK variable makes it ANSI:
text = $ ¢ £ €

Transform, Clipboard, Unicode, %text%

ANSI = %ClipBoard%

MsgBox %ANSI% ; <-- process as you need it


PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
If you don't want to use the clipboard, here is a more convoluted way:
textToConvert = « – € œ Œ — »
textLength := StrLen(textToConvert)
VarSetCapacity(uniText, textLength * 2, 0) ; Worse case (all Ascii)
r := DllCall("MultiByteToWideChar"
		, "UInt", 65001        ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
		, "UInt", 0            ; dwFlags
		, "Str", textToConvert ; LPSTR lpMultiByteStr
		, "Int", textLength    ; cbMultiByte: -1=null terminated
		, "UInt", &uniText     ; LPCWSTR lpWideCharStr
		, "Int", textLength)   ; cchWideChar: 0 to get required size
VarSetCapacity(ansiText, textLength, 0)
r := DllCall("WideCharToMultiByte"
		, "UInt", 0            ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
		, "UInt", 0            ; dwFlags
		, "Str", uniText       ; LPCWSTR lpWideCharStr
		, "Int", textLength    ; cchWideChar: size in WCHAR values, -1=null terminated
		, "Str", ansiText      ; LPSTR lpMultiByteStr
		, "Int", textLength    ; cbMultiByte: 0 to get required size
		, "UInt", 0            ; LPCSTR lpDefaultChar
		, "UInt", 0)           ; LPBOOL lpUsedDefaultChar
MsgBox % ansiText

Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

TheIrishThug
  • Members
  • 419 posts
  • Last active: Jan 18 2012 02:51 PM
  • Joined: 19 Mar 2006
Thanks for the help.

Phil, I think I am just going to stick with using SavedClip := ClipboardAll.

BoBo
  • Guests
  • Last active:
  • Joined: --

If you don't want to use the clipboard, here is a more convoluted way

Wouldn't this be perfectly to be posted at the Script&Functions Section ?!! :D

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

Wouldn't this be perfectly to be posted at the Script&Functions Section ?!! :D

Good idea, I begin to have a collection of Unicode related snippets: Read and Write Unicode
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")