chars replacement

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
sokrakes
Posts: 36
Joined: 07 Aug 2019, 01:40

chars replacement

12 Jan 2024, 17:52

Hi,
In version 1 I had "chars replacement" like this, in version 2 I can't find the correct definition of "chars".
Or do you know a better way to replace characters?

Code: Select all

^F1::{

myString := ""
Send("^c")
myString := A_Clipboard
chars := {"á": "a"
         ,"č": "%C4%8D"
         ,"d":"[ďđð]"
         ,"é":"%C3%A9"
         ,"ě":"%C4%9B"
         ,"g":"[ğĝġģ]"
         ,"h":"[ĥħ]"
         ,"í":"%C3%AD"
         ,"j":"[ĵ]"
         ,"k":"[ķ]"
         ,"l":"[ĺľļłŀ]"
         ,"n":"[ńňñņ]"
         ,"o":"[óòŏôốồỗổǒöőõøǿōỏơớờỡởợọộ]"
         ,"p":"[ṕṗ]"
         ,"ř":"%C5%99"
         ,"š":"%C5%A1"
         ,"t":"[ťţŧ]"
         ,"u":"[úùŭûǔůüǘǜǚǖűũųūủưứừữửựụ]"
         ,"w":"[ẃẁŵẅ]"
         ,"y":"[ýỳŷÿỹỷỵ]"
         ,"z":"[źžż]"
         ,"/":"%2F"}

for find, replace in chars
    myString := RegExReplace(myString, find, replace)

A_Clipboard := myString
}
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: chars replacement

12 Jan 2024, 18:01

What you are referring to as "chars" is an associative array, which in v2 is a Map object.

Code: Select all

#Requires AutoHotkey v2.0
^F1::{
	myString := ""
	A_Clipboard := ""
	Send("^c")
	if !(ClipWait, 1)
		return
	myString := A_Clipboard
	chars := Map("á","a"
			,"č","%C4%8D"
			,"d","[ďđð]"
			,"é","%C3%A9"
			,"ě","%C4%9B"
			,"g","[ğĝġģ]"
			,"h","[ĥħ]"
			,"í","%C3%AD"
			,"j","[ĵ]"
			,"k","[ķ]"
			,"l","[ĺľļłŀ]"
			,"n","[ńňñņ]"
			,"o","[óòŏôốồỗổǒöőõøǿōỏơớờỡởợọộ]"
			,"p","[ṕṗ]"
			,"ř","%C5%99"
			,"š","%C5%A1"
			,"t","[ťţŧ]"
			,"u","[úùŭûǔůüǘǜǚǖűũųūủưứừữửựụ]"
			,"w","[ẃẁŵẅ]"
			,"y","[ýỳŷÿỹỷỵ]"
			,"z","[źžż]"
			,"/","%2F")

	for find, replace in chars
		myString := RegExReplace(myString, find, replace)

	A_Clipboard := myString
}
User avatar
andymbody
Posts: 950
Joined: 02 Jul 2017, 23:47

Re: chars replacement

12 Jan 2024, 18:29

Map doesn't seem to support certain chars (192+) as keys... is this a bug, or something I am doing wrong?

This doesn't work for me
chars := Map("á", "a")

gives error
Missing """
sokrakes
Posts: 36
Joined: 07 Aug 2019, 01:40

Re: chars replacement

12 Jan 2024, 19:05

Thanks so much for the directions, I don't speak English so it's a bit more challenging to find, to get my bearings.

Code: Select all

#Requires AutoHotkey v2.0
^F1::{
	myString := ""
	send("^c")
	if !(ClipWait, 1)
		return
	myString := A_Clipboard
	chars := Map("%C4%8D","č",
				"%C3%A9","é",
				"%C4%9B","ě",
				"%C3%AD","í",
				"%C5%99","ř",
				"%C5%A1","š",
				"%252F","/",)

	for find, replace in chars
		myString := RegExReplace(myString, find, replace)

	A_Clipboard := myString
}
Last edited by sokrakes on 12 Jan 2024, 19:06, edited 1 time in total.
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: chars replacement

12 Jan 2024, 19:06

andymbody wrote:
12 Jan 2024, 18:29
Map doesn't seem to support certain chars (192+) as keys... is this a bug, or something I am doing wrong?

This doesn't work for me
chars := Map("á", "a")

gives error
Missing """
chars := Map("á", "a") works on my end.
The only way to get that error on my end is to have the wrong encoding on the file itself, like ANSI instead of UTF-8. Whichever code editor you are using, make sure it supports UTF-8.
User avatar
andymbody
Posts: 950
Joined: 02 Jul 2017, 23:47

Re: chars replacement

12 Jan 2024, 19:19

coffee wrote:
12 Jan 2024, 19:06
The only way to get that error on my end is to have the wrong encoding on the file itself, like ANSI instead of UTF-8.
That was it... Thanks

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Draken, lexikos and 22 guests