Not Working StrReplace Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
hasantr
Posts: 279
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Not Working StrReplace

21 Aug 2019, 01:14

Why won't this work?

Code: Select all

aramaMetni := "AĞŞAMÇAçaÜüiIöÖ"
trKarakter := {"c":"Ç","c":"ç","i":"İ","i":"ı","s":"Ş","s":"ş","g":"Ğ","g":"ğ","o":"Ö","o":"ö","u":"Ü","u":"ü"}
for,KEY,VAL in trKarakter
	aramaMetni := StrReplace(aramaMetni,VAL,KEY,,ALL)
MsgBox % aramaMetni
Thansk.
User avatar
Xtra
Posts: 1474
Joined: 02 Oct 2015, 12:15

Re: Not Working StrReplace

21 Aug 2019, 01:25

Use -1 instead of All
All is for StringReplace not StrReplace()
Rohwedder
Posts: 2299
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Not Working StrReplace

21 Aug 2019, 01:50

Hallo,
I think you got KEY and VAL mixed up, too:

Code: Select all

aramaMetni := "AĞŞAMÇAçaÜüiIöÖ"
trKarakter := {"Ç":"c","ç":"c","İ":"i","ı":"i","Ş":"s","ş":"s","Ğ":"g","ğ":"g","Ö":"o","ö":"o","Ü":"u","ü":"u"}
for KEY,VAL in trKarakter
	aramaMetni := StrReplace(aramaMetni,KEY,VAL)
MsgBox % aramaMetni
User avatar
jeeswg
Posts: 6841
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Not Working StrReplace  Topic is solved

21 Aug 2019, 02:04

I might do something like this:

Code: Select all

q:: ;replace characters (strip accents)
vText := "AĞŞAMÇAçaÜüiIöÖ"
vList := "Çc,çc,İi,ıi,Şs,şs,Ğg,ğg,Öo,öo,Üu,üu"
StringCaseSense, On
Loop Parse, vList, % ","
{
	vChar1 := SubStr(A_LoopField, 1, 1)
	vChar2 := SubStr(A_LoopField, 2, 1)
	vText := StrReplace(vText, StrUpper(vChar1), StrUpper(vChar2))
	vText := StrReplace(vText, StrLower(vChar1), StrLower(vChar2))
}
MsgBox, % vText
return

;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689
StrLower(String, T:="")
{
	local OutputVar := ""
	StringLower, OutputVar, String, % T
	return OutputVar
}
StrUpper(String, T:="")
{
	local OutputVar := ""
	StringUpper, OutputVar, String, % T
	return OutputVar
}
Btw watch out that for keys regarded as identical (e.g. Latin alphabet, case insensitive), later keys overwrite earlier keys.

Code: Select all

oMap := {a:1, A:2}
MsgBox, % oMap.Count() ;1
MsgBox, % oMap.a ;2
MsgBox, % oMap.A ;2
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
hasantr
Posts: 279
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Not Working StrReplace

21 Aug 2019, 02:58

jeeswg wrote:
21 Aug 2019, 02:04
I might do something like this:

Code: Select all

q:: ;replace characters (strip accents)
vText := "AĞŞAMÇAçaÜüiIöÖ"
vList := "Çc,çc,İi,ıi,Şs,şs,Ğg,ğg,Öo,öo,Üu,üu"
StringCaseSense, On
Loop Parse, vList, % ","
{
	vChar1 := SubStr(A_LoopField, 1, 1)
	vChar2 := SubStr(A_LoopField, 2, 1)
	vText := StrReplace(vText, StrUpper(vChar1), StrUpper(vChar2))
	vText := StrReplace(vText, StrLower(vChar1), StrLower(vChar2))
}
MsgBox, % vText
return

;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689
StrLower(String, T:="")
{
	local OutputVar := ""
	StringLower, OutputVar, String, % T
	return OutputVar
}
StrUpper(String, T:="")
{
	local OutputVar := ""
	StringUpper, OutputVar, String, % T
	return OutputVar
}
Btw watch out that for keys regarded as identical (e.g. Latin alphabet, case insensitive), later keys overwrite earlier keys.

Code: Select all

oMap := {a:1, A:2}
MsgBox, % oMap.Count() ;1
MsgBox, % oMap.a ;2
MsgBox, % oMap.A ;2
Thanks was great.
User avatar
hasantr
Posts: 279
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Not Working StrReplace

21 Aug 2019, 02:59

Is this?

Code: Select all

bas := InStr(pano,"<![CDATA[") + 9 ; Returns 4
son := InStr(pano,"]]></") - bas
MsgBox SubStr(pano,bas,son)
Or this?

Code: Select all

MsgBox % SubStr(pano,InStr(pano,"<![CDATA[") + 9,InStr(pano,"]]></") - InStr(pano,"<![CDATA[") - 9)
Which would be more efficient?

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], Gully, JoeWinograd, MrGrayline and 124 guests