Find and replace accented characters
Hello
Same problem as yesterday
I think I have a valid script/command/file (or whatever you call it) found on the AHK website (this is in the akh file)
MsgBox % StrUnmark("ÁáÀàÂâǍǎĂăÃãẢảẠạÄäÅåĀāĄąẤấẦầẪẫẨẩẬậẮắẰằẴẵẲẳẶặǺǻĆćĈĉČčĊċÇçĎďĐđÐÉéÈèÊêĚěĔĕẼẽẺẻĖėËëĒēĘęẾếỀềỄễỂểẸẹỆệĞğĜĝĠġĢģĤĥĦħÍíÌìĬĭÎîǏǐÏïĨĩĮįĪīỈỉỊịĴĵĶķĹ弾ĻļŁłĿŀŃńŇňÑñŅņÓóÒòŎŏÔôỐốỒồỖỗỔổǑǒÖöŐőÕõØøǾǿŌōỎỏƠơỚớỜờỠỡỞởỢợỌọỘộṔṕṖṗŔŕŘřŖŗŚśŜŝŠšŞşŤťŢţŦŧÚúÙùŬŭÛûǓǔŮůÜüǗǘǛǜǙǚǕǖŰűŨũŲųŪūỦủƯưỨứỪừỮữỬửỰựỤụẂẃẀẁŴŵẄẅÝýỲỳŶŷŸÿỸỹỶỷỴỵŹźŽžŻż")
; Removes marks from letters. Requires Windows Vista or later.
StrUnmark(string) {
chars := {"a":"ⱥ","b":"ƀ","c":"ȼ","d":"đ","e":"ɇ","f":"ꞙ","g":"ǥ","h":"ħ","i":"ɨ"
,"j":"[ɉʄɟ]","k":"[ꝅꝁꞣꝃ]","l":"[łꝉŀ]","n":"ꞥ","o":"[ᴓꬿǿꝋꬾø]","p":"[ꝑᵽ]"
,"q":"[ꝗꝙ]","r":"[ɍꞧ]","s":"ꞩ","t":"[ŧⱦ]","v":"ꝟ","y":"ɏ","z":"ƶ"}
string := RegExReplace(string,"Ð","D")
For repl, find in chars
{
StringUpper, urepl, repl
StringUpper, ufind, find
string := RegExReplace(string,find,repl)
, string := RegExReplace(string,ufind,urepl)
}
len := DllCall("Normaliz.dll\NormalizeString", "int", 2
, "wstr", string, "int", StrLen(string)
, "ptr", 0, "int", 0) ; Get *estimated* required buffer size.
Loop {
VarSetCapacity(buf, len * 2)
len := DllCall("Normaliz.dll\NormalizeString", "int", 2
, "wstr", string, "int", StrLen(string)
, "ptr", &buf, "int", len)
if len >= 0
break
if (A_LastError != 122) ; ERROR_INSUFFICIENT_BUFFER
return
len *= -1 ; This is the new estimate.
}
; Remove combining marks and return result.
return RegExReplace(StrGet(&buf, len, "UTF-16"), "\pM")
}
but once again, I can't seem to install it
Either I get an error when trying to install it or there is no error but then it does not run when I use my shortcut
Currently, i have the ahk file in
%dir%\REMOVE ACCENTS FROM FILE NAMES.ahk
I've tried ticking hooks and even wildcards as I see the file makes reference to regex
Can anyone help please?
Same problem as yesterday
I think I have a valid script/command/file (or whatever you call it) found on the AHK website (this is in the akh file)
MsgBox % StrUnmark("ÁáÀàÂâǍǎĂăÃãẢảẠạÄäÅåĀāĄąẤấẦầẪẫẨẩẬậẮắẰằẴẵẲẳẶặǺǻĆćĈĉČčĊċÇçĎďĐđÐÉéÈèÊêĚěĔĕẼẽẺẻĖėËëĒēĘęẾếỀềỄễỂểẸẹỆệĞğĜĝĠġĢģĤĥĦħÍíÌìĬĭÎîǏǐÏïĨĩĮįĪīỈỉỊịĴĵĶķĹ弾ĻļŁłĿŀŃńŇňÑñŅņÓóÒòŎŏÔôỐốỒồỖỗỔổǑǒÖöŐőÕõØøǾǿŌōỎỏƠơỚớỜờỠỡỞởỢợỌọỘộṔṕṖṗŔŕŘřŖŗŚśŜŝŠšŞşŤťŢţŦŧÚúÙùŬŭÛûǓǔŮůÜüǗǘǛǜǙǚǕǖŰűŨũŲųŪūỦủƯưỨứỪừỮữỬửỰựỤụẂẃẀẁŴŵẄẅÝýỲỳŶŷŸÿỸỹỶỷỴỵŹźŽžŻż")
; Removes marks from letters. Requires Windows Vista or later.
StrUnmark(string) {
chars := {"a":"ⱥ","b":"ƀ","c":"ȼ","d":"đ","e":"ɇ","f":"ꞙ","g":"ǥ","h":"ħ","i":"ɨ"
,"j":"[ɉʄɟ]","k":"[ꝅꝁꞣꝃ]","l":"[łꝉŀ]","n":"ꞥ","o":"[ᴓꬿǿꝋꬾø]","p":"[ꝑᵽ]"
,"q":"[ꝗꝙ]","r":"[ɍꞧ]","s":"ꞩ","t":"[ŧⱦ]","v":"ꝟ","y":"ɏ","z":"ƶ"}
string := RegExReplace(string,"Ð","D")
For repl, find in chars
{
StringUpper, urepl, repl
StringUpper, ufind, find
string := RegExReplace(string,find,repl)
, string := RegExReplace(string,ufind,urepl)
}
len := DllCall("Normaliz.dll\NormalizeString", "int", 2
, "wstr", string, "int", StrLen(string)
, "ptr", 0, "int", 0) ; Get *estimated* required buffer size.
Loop {
VarSetCapacity(buf, len * 2)
len := DllCall("Normaliz.dll\NormalizeString", "int", 2
, "wstr", string, "int", StrLen(string)
, "ptr", &buf, "int", len)
if len >= 0
break
if (A_LastError != 122) ; ERROR_INSUFFICIENT_BUFFER
return
len *= -1 ; This is the new estimate.
}
; Remove combining marks and return result.
return RegExReplace(StrGet(&buf, len, "UTF-16"), "\pM")
}
but once again, I can't seem to install it
Either I get an error when trying to install it or there is no error but then it does not run when I use my shortcut
Currently, i have the ahk file in
%dir%\REMOVE ACCENTS FROM FILE NAMES.ahk
I've tried ticking hooks and even wildcards as I see the file makes reference to regex
Can anyone help please?
This script attempts to remove the accented characters from the string - it works for me. I simply copied your code to the command field in FastKeys.
Type: Command
Command:
Type: Command
Command:
Code: Select all
MsgBox % StrUnmark("ÁáÀàÂâǍǎĂăÃãẢảẠạÄäÅåĀāĄąẤấẦầẪẫẨẩẬậẮắẰằẴẵẲẳẶặǺǻĆćĈĉČčĊċÇçĎďĐđÐÉéÈèÊêĚěĔĕẼẽẺẻĖėËëĒēĘęẾếỀềỄễỂểẸẹỆệĞğĜĝĠġĢģĤĥĦħÍíÌìĬĭÎîǏǐÏïĨĩĮįĪīỈỉỊịĴĵĶķĹ弾ĻļŁłĿŀŃńŇňÑñŅņÓóÒòŎŏÔôỐốỒồỖỗỔổǑǒÖöŐőÕõØøǾǿŌōỎỏƠơỚớỜờỠỡỞởỢợỌọỘộṔṕṖṗŔŕŘřŖŗŚśŜŝŠšŞşŤťŢţŦŧÚúÙùŬŭÛûǓǔŮůÜüǗǘǛǜǙǚǕǖŰűŨũŲųŪūỦủƯưỨứỪừỮữỬửỰựỤụẂẃẀẁŴŵẄẅÝýỲỳŶŷŸÿỸỹỶỷỴỵŹźŽžŻż")
; Removes marks from letters. Requires Windows Vista or later.
StrUnmark(string) {
chars := {"a":"ⱥ","b":"ƀ","c":"ȼ","d":"đ","e":"ɇ","f":"ꞙ","g":"ǥ","h":"ħ","i":"ɨ"
,"j":"[ɉʄɟ]","k":"[ꝅꝁꞣꝃ]","l":"[łꝉŀ]","n":"ꞥ","o":"[ᴓꬿǿꝋꬾø]","p":"[ꝑᵽ]"
,"q":"[ꝗꝙ]","r":"[ɍꞧ]","s":"ꞩ","t":"[ŧⱦ]","v":"ꝟ","y":"ɏ","z":"ƶ"}
string := RegExReplace(string,"Ð","D")
For repl, find in chars
{
StringUpper, urepl, repl
StringUpper, ufind, find
string := RegExReplace(string,find,repl)
, string := RegExReplace(string,ufind,urepl)
}
len := DllCall("Normaliz.dll\NormalizeString", "int", 2
, "wstr", string, "int", StrLen(string)
, "ptr", 0, "int", 0) ; Get *estimated* required buffer size.
Loop {
VarSetCapacity(buf, len * 2)
len := DllCall("Normaliz.dll\NormalizeString", "int", 2
, "wstr", string, "int", StrLen(string)
, "ptr", &buf, "int", len)
if len >= 0
break
if (A_LastError != 122) ; ERROR_INSUFFICIENT_BUFFER
return
len *= -1 ; This is the new estimate.
}
; Remove combining marks and return result.
return RegExReplace(StrGet(&buf, len, "UTF-16"), "\pM")
}
Hello Tom
It installs okay for me and when I select the string with accented letters and press on the shortcut, the messenger window comes up and I click on okay but then nothing happens.
Any ideas please?
Thanks
It installs okay for me and when I select the string with accented letters and press on the shortcut, the messenger window comes up and I click on okay but then nothing happens.
Any ideas please?
Thanks
This script removes accented characters from selected string:
Shortcut:
Type: Command
Shortcut:
Type: Command
Code: Select all
Clipboard:=""
Send, ^c
ClipWait
SendInput, % StrUnmark(Clipboard)
return
; Removes marks from letters. Requires Windows Vista or later.
StrUnmark(string) {
chars := {"a":"ⱥ","b":"ƀ","c":"ȼ","d":"đ","e":"ɇ","f":"ꞙ","g":"ǥ","h":"ħ","i":"ɨ"
,"j":"[ɉʄɟ]","k":"[ꝅꝁꞣꝃ]","l":"[łꝉŀ]","n":"ꞥ","o":"[ᴓꬿǿꝋꬾø]","p":"[ꝑᵽ]"
,"q":"[ꝗꝙ]","r":"[ɍꞧ]","s":"ꞩ","t":"[ŧⱦ]","v":"ꝟ","y":"ɏ","z":"ƶ"}
string := RegExReplace(string,"Ð","D")
For repl, find in chars
{
StringUpper, urepl, repl
StringUpper, ufind, find
string := RegExReplace(string,find,repl)
, string := RegExReplace(string,ufind,urepl)
}
len := DllCall("Normaliz.dll\NormalizeString", "int", 2
, "wstr", string, "int", StrLen(string)
, "ptr", 0, "int", 0) ; Get *estimated* required buffer size.
Loop {
VarSetCapacity(buf, len * 2)
len := DllCall("Normaliz.dll\NormalizeString", "int", 2
, "wstr", string, "int", StrLen(string)
, "ptr", &buf, "int", len)
if len >= 0
break
if (A_LastError != 122) ; ERROR_INSUFFICIENT_BUFFER
return
len *= -1 ; This is the new estimate.
}
; Remove combining marks and return result.
return RegExReplace(StrGet(&buf, len, "UTF-16"), "\pM")
}
Hello Tom
Wow, that now works thanks
I see that you added something at the start even though I still don't really understand it.
I did try to read the starters tutorial in AHK but it's really not adapted for beginners. the FastKeys help pages seem a bit better to me for beginners
A couple of years ago, I needed to learn regular expressions, at least simple ones and that was a real effort. I just can't see my mastering scripts at my age so I need to bum them off people.
So I'm very helpful for any help that I get.
Wow, that now works thanks
I see that you added something at the start even though I still don't really understand it.
I did try to read the starters tutorial in AHK but it's really not adapted for beginners. the FastKeys help pages seem a bit better to me for beginners
A couple of years ago, I needed to learn regular expressions, at least simple ones and that was a real effort. I just can't see my mastering scripts at my age so I need to bum them off people.
So I'm very helpful for any help that I get.
-
- Posts: 18
- Joined: Jul 30th, ’20, 08:24
Thanks for this code, awesome!
How should I modify this for change spaces and dots to _?
like
abc def -> abc_def
abc.def -> abc_def
I want to use it for making safenames
Thanks
How should I modify this for change spaces and dots to _?
like
abc def -> abc_def
abc.def -> abc_def
I want to use it for making safenames
Thanks
This replaces all spaces and dots in selected string to underscores ("_").
Code: Select all
Clipboard:=""
Send, ^c
ClipWait
string:=clipboard
stringreplace, string, string, %A_Space%, _, all
stringreplace, string, string, ., _, all
SendInput, % string
return
-
- Posts: 18
- Joined: Jul 30th, ’20, 08:24
@tom Thank you very much! I really want o give you a like or something but there is no button for that...
The script for removing accented characters isn't working quite right for me.
It adds random blank lines to the converted text
Text before
text after
Win 10, encoding utf-8
It adds random blank lines to the converted text
Text before
Code: Select all
Požadavky na stav aplikace před nasazením verze
Akce před instalací
Návod na instalaci programového vybavení pro konverzi databáze
Návod na konverzi databáze
Popis konverzních programů
Souhrnný přehled protokolů z konverzí
Návod na instalaci aplikačního programového vybavení
Akce po instalaci
Postup po neúspěšné konverzi databáze
Nové/změněné datové objekty a jejich vazby na aplikační úlohy
Změny v číselnících
Postup pro nepřerušený provoz středisek
text after
Code: Select all
Pozadavky na stav aplikace pred nasazenim verze
Akce pred instalaci
Navod na instalaci programoveho vybaveni pro konverzi databaze
Navod na konverzi databaze
Popis konverznich programu
Souhrnny prehled protokolu z konverzi
Navod na instalaci aplikacniho programoveho vybaveni
Akce po instalaci
Postup po neuspesne konverzi databaze
Nove/zmenene datove objekty a jejich vazby na aplikacni ulohy
Zmeny v ciselnicich
Postup pro nepreruseny provoz stredisek
Win 10, encoding utf-8
Replace the line 4 in the script with
Code: Select all
SendInput, % StrUnmark(StrReplace(Clipboard,"`r"))