Read file with special characters Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Read file with special characters

Post by Ecimeric » 06 May 2021, 17:37

Code: Select all

		Array := []
		Loop, Read, file.txt
			Array.Push(StrSplit(A_LoopReadLine, ","))
How can I adapt this code to read special characters in file.txt properly?
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Read file with special characters

Post by mikeyww » 06 May 2021, 18:19

Code: Select all

Array := []
Loop, Read, %A_ScriptDir%\test.txt
 For k, v in StrSplit(A_LoopReadLine, ",")
  Array.Push(v)
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Re: Read file with special characters

Post by Ecimeric » 06 May 2021, 19:14

Code: Select all

		Array := []
		Loop, Read, file.txt
			for k, v in (StrSplit(A_LoopReadLine, ","))
                Array.Push(v)
		for index, element in Array
			Menu, MySubmenu2, Add, % element.1, Function
        Menu, MySubmenu, Add, MenuItemName, :MySubmenu2
I did not expect the subsequent code to be relevant, but I am getting a submenu does not exist error.

To clarify: I am trying to get characters like ü to render in MySubmenu2.
Last edited by Ecimeric on 06 May 2021, 19:29, edited 1 time in total.
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Read file with special characters

Post by mikeyww » 06 May 2021, 19:16

If you provide an example of the file and the desired effect or output, along with a description of what the script should do, the coding will be more straightforward.
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Re: Read file with special characters

Post by Ecimeric » 06 May 2021, 19:31

The file looks like Söme wörds,1,234,abc. I want to render Söme wörds in MySubmenu2 instead of having ö appear as gibberish.
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Read file with special characters  Topic is solved

Post by mikeyww » 06 May 2021, 19:40

This worked at my end.

Code: Select all

Loop, Read, %A_ScriptDir%\temp.txt
 For k, v in StrSplit(A_LoopReadLine, ",")
  Menu, MySubmenu2, Add, %v%, Function
Menu, MySubmenu, Add, Test, :MySubmenu2
Menu, MySubmenu, Show
Return
With only a single line in the file, you do not need a loop.

You might have to save your AHK script file, or your text file, as UTF-8 with BOM signature.
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Re: Read file with special characters

Post by Ecimeric » 06 May 2021, 20:59

Changing the text file from UTF-8 to UTF-8-BOM did the trick.
Post Reply

Return to “Ask for Help (v1)”