Page 2 of 2

Re: InStr(...) gives error?

Posted: 17 Apr 2024, 12:23
by Archimede
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.

Re: InStr(...) gives error?

Posted: 17 Apr 2024, 13:27
by kunkel321
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.

Re: InStr(...) gives error?

Posted: 18 Apr 2024, 02:15
by just me
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.

Re: InStr(...) gives error?

Posted: 18 Apr 2024, 11:54
by rommmcek
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.

Re: InStr(...) gives error?

Posted: 19 Apr 2024, 16:23
by rommmcek
I modified the code above and it seems to solve the issue.