InStr(...) gives error?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Archimede
Posts: 541
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: InStr(...) gives error?

Post by Archimede » 17 Apr 2024, 12:23

Can anyone tell me how I can automatically substitute all "xE9" special character ( and other similar ) with another character I want?
I use the SciTE4AutoHotkey editor.
Thank you very much.

User avatar
kunkel321
Posts: 1133
Joined: 30 Nov 2015, 21:19

Re: InStr(...) gives error?

Post by kunkel321 » 17 Apr 2024, 13:27

Archimede wrote:
17 Apr 2024, 12:23
Can anyone tell me how I can automatically substitute all "xE9" special character ( and other similar ) with another character I want?
I use the SciTE4AutoHotkey editor.
Thank you very much.
Did these "xE9" characters appear when you changed the file to UTF encoding?

If so, see my previous recommendation about first, creating the file, and then, pasting your code into the file.

Hopefully you saved a back-up before you converted the file. If not, check the folder for a .BAK file, which might have a previous version.
ste(phen|ve) kunkel

just me
Posts: 9528
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: InStr(...) gives error?

Post by just me » 18 Apr 2024, 02:15

Your issue seems to be caused by the fact that SciTE expects UTF-8 but gets ANSI. Most single characters above 127 are invalid in UTF-8. Only some are permitted as leading characters of character sequences used to encode a single character. The è is 0xE9/235 and thus invalid UTF-8. SciTE seems to mark invalid characters as xXX using their hex value.

User avatar
rommmcek
Posts: 1479
Joined: 15 Aug 2014, 15:18

Re: InStr(...) gives error?

Post by rommmcek » 18 Apr 2024, 11:54

Try:

Code: Select all

#Requires AutoHotkey v2+
#SingleInstance Force

Loop Files, "*.ahk" {
    if !FileExist(utf8FilePath:= A_ScriptDir "\" (Utf_Files:= "UTF8_Files") "\" StrReplace(A_LoopFileName, "." A_LoopFileExt) "_UTF-8." A_LoopFileExt) {
        ansiContent:= FileRead(A_LoopFileName, "CP1252")
        if !DirExist(Utf_Files)
            DirCreate Utf_Files
        FileAppend ansiContent, utf8FilePath, "UTF-8"
    }
    If GetKeyState("Esc", "P")
        Break
}

SoundBeep(8000), SoundBeep(4000)
P.s.: Save the script in the folder where you have your Ahk scripts. It will copy all (ANSI & UTF-8) of your scripts (for safety) to subfolder UTF8_Files appending "_UTF-8" to each file name (before ".ahk" extension) and save them as (you guessed it) UTF-8. Script is safe and works for me.

Note:
just me wrote:
18 Apr 2024, 02:15
Your issue seems to be caused by the fact that SciTE expects UTF-8 but gets ANSI...
Indeed for SciTE my script does not work, sorry for confusion.
The code is modified and works for me properly even in SciTE.
Last edited by rommmcek on 19 Apr 2024, 17:49, edited 3 times in total.

User avatar
rommmcek
Posts: 1479
Joined: 15 Aug 2014, 15:18

Re: InStr(...) gives error?

Post by rommmcek » 19 Apr 2024, 16:23

I modified the code above and it seems to solve the issue.

Post Reply

Return to “Ask for Help (v2)”