Page 1 of 1
simple iniwrite
Posted: 26 Jan 2022, 07:49
by LC_1
Hello everybody,
only a small queston: whats wrong in my code??
Code: Select all
IniRead, string_to, C:\XX\auto_replace.ini, Section1, replace_to
string_to := StrReplace(string_to, "A", "B")
IniWrite % string_to, C:\XX\auto_replace.ini, Section1, replace_to
no string is writing in ini file.
Thanks
Re: simple iniwrite
Posted: 26 Jan 2022, 08:03
by boiler
Put this line after the IniRead and before the IniWrite to see what the variable actually contains:
Do you perhaps have a typo in the path to the ini file? Put this at the top of your script (replacing XX as necessary, of course):
Code: Select all
MsgBox, % "Ini file " . (FileExist("C:\XX\auto_replace.ini") ? "found" : "not found")
Can you post the contents of your ini file?
Re: simple iniwrite
Posted: 26 Jan 2022, 08:42
by LC_1
Ini file is correctly read, and replace_to string content is regurarly show in the msgbox. Something wrong in write function.
This is ini file content:
Code: Select all
[Section1]
replace_from=text_from
replace_to=text_to
Re: simple iniwrite
Posted: 26 Jan 2022, 09:20
by BoBo
Code: Select all
/*
[Section1]
replace_to=1AAAAAA2
*/
IniRead, string_to, % A_ScriptName, Section1, replace_to
MsgBox % string_to := StrReplace(string_to, "A", "B")
IniWrite % string_to, % A_ScriptName, Section1, replace_to
; check your scripts "ini section" for changes, probably you've to "refresh" the open file with pushing F5!
Re: simple iniwrite Topic is solved
Posted: 26 Jan 2022, 09:23
by boiler
@LC_1 - What are you expecting to be written to it? You haven’t changed anything in in the string
text_to when you’re replacing A with B. The ini file you showed would correctly look the same before and after running your script.
Perhaps you meant to read from
replace_from instead of
replace_to:
Code: Select all
IniRead, string_to, C:\XX\auto_replace.ini, Section1, replace_from
string_to := StrReplace(string_to, "A", "B")
IniWrite % string_to, C:\XX\auto_replace.ini, Section1, replace_to
Re: simple iniwrite
Posted: 26 Jan 2022, 12:08
by LC_1
I'm sorry, I was using uncorrect variable name during writing process.
Thank you all.