Page 1 of 1

Not Working StrReplace

Posted: 21 Aug 2019, 01:14
by hasantr
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.

Re: Not Working StrReplace

Posted: 21 Aug 2019, 01:25
by Xtra
Use -1 instead of All
All is for StringReplace not StrReplace()

Re: Not Working StrReplace

Posted: 21 Aug 2019, 01:50
by Rohwedder
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

Re: Not Working StrReplace  Topic is solved

Posted: 21 Aug 2019, 02:04
by jeeswg
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

Re: Not Working StrReplace

Posted: 21 Aug 2019, 02:58
by hasantr
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.

Re: Not Working StrReplace

Posted: 21 Aug 2019, 02:59
by hasantr
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?