String Format

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Alcrkai
Posts: 47
Joined: 16 Mar 2021, 10:51

String Format

Post by Alcrkai » 26 Jul 2021, 06:45

How to format a string to remove the accent. I need to leave it in lowercase and without accents, to make it lowercase I use StringLower but to remove the accent?

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: String Format

Post by boiler » 26 Jul 2021, 06:48

You could use StrReplace() with a for loop to loop through an associative array of accented characters and their replacements as key-value pairs.

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: String Format

Post by boiler » 26 Jul 2021, 07:13

Example:

Code: Select all

MsgBox, % UnAccent("móstrame qué hacer")
return

UnAccent(str) {
	static chars := {"á": "a", "é": "e", "í": "i", "ó": "o", "ü": "u", "ñ": "n"}
	for accented, unaccented in chars
		str := StrReplace(str, accented, unaccented)
	return str
}

gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

Re: String Format

Post by gregster » 26 Jul 2021, 07:16

I think this code by lexikos can help to remove the diacritics: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=8089#p47548

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: String Format

Post by boiler » 26 Jul 2021, 07:19

Thanks for that, gregster. Looks like I was thinking along the same lines as another poster in that thread.

Post Reply

Return to “Ask for Help (v1)”