shay Posted January 26, 2009 Share Posted January 26, 2009 Hii try to add new "key+value" to INI filei need to add verbose = 5using the command : IniWrite ( "test.ini", "control", "verbose", "5" )i get line that look like that: verbose=5but i need [space] after the word and after the = (verbose = 5)without the space my software wont recognize the line.Shay "If the facts don't fit the theory, change the facts." Albert Einstein Link to comment Share on other sites More sharing options...
Inverted Posted January 26, 2009 Share Posted January 26, 2009 What about "verbose " and " 5" ? Link to comment Share on other sites More sharing options...
GaRydelaMer Posted January 26, 2009 Share Posted January 26, 2009 Hi, try this, when you're finish to add new key+values Local $s = FileRead("test.ini") $s = StringRegExpReplace($s, "(.*)=(.*)", "$1 = $2") ConsoleWrite($s) FileWrite("test.ini", $s) sorry for my english, i'm french Link to comment Share on other sites More sharing options...
shay Posted January 26, 2009 Author Share Posted January 26, 2009 What about "verbose " and " 5" ? i try that but i got [sPACE] only before the 5 verbose= 5 "If the facts don't fit the theory, change the facts." Albert Einstein Link to comment Share on other sites More sharing options...
GaRydelaMer Posted January 26, 2009 Share Posted January 26, 2009 No pbchange pattern in the rex expression$s = StringRegExpReplace($s, "(.*)=(.*)", "$1= $2") Link to comment Share on other sites More sharing options...
shay Posted January 26, 2009 Author Share Posted January 26, 2009 Hi, try this, when you're finish to add new key+values Local $s = FileRead("test.ini") $s = StringRegExpReplace($s, "(.*)=(.*)", "$1 = $2") ConsoleWrite($s) FileWrite("test.ini", $s) sorry for my english, i'm french that ok my English is no so good to but your script didn't help still no [sPACE] "If the facts don't fit the theory, change the facts." Albert Einstein Link to comment Share on other sites More sharing options...
shay Posted January 26, 2009 Author Share Posted January 26, 2009 that ok my English is no so good to but your script didn't help still no [sPACE] my bad, its work ok!! but it add [sPACE] to all the other "keys" in my INI file how can i add it only to this specific line "If the facts don't fit the theory, change the facts." Albert Einstein Link to comment Share on other sites More sharing options...
GaRydelaMer Posted January 26, 2009 Share Posted January 26, 2009 (edited) Or more simply ; here for one ; Why you noy use this ?? Local $key = "verbose", $val = 5 IniWrite("test.ini", "control", $key, " " & $val) ; here for all ;Or if you run more one time this reqexp change to: Local $s = FileRead("test.ini") $s = StringRegExpReplace($s, "(\w*)(\s*)=(\s*)(\w*)", "$1= $4") ;for specific keys, but in all section with the same key Local $key = "verbose" $s = StringRegExpReplace($s, "(" & $ key & ")(\s*)=(\s*)(\w*)", "$1= $4") ConsoleWrite($s) FileDelete("test.ini"); delete the file before rewriting because filewrite add line(s) at the end of file FileWrite("test.ini", $s) Edited January 26, 2009 by GaRydelaMer Link to comment Share on other sites More sharing options...
shay Posted January 27, 2009 Author Share Posted January 27, 2009 i try this with no luck still "verbose= 5" (no space) Local $key = "verbose", $val = 5 IniWrite("test.ini", "control", $key, " " & $val) Local $key = "verbose" $s = StringRegExpReplace($s, "(" & $key & ")(\s*)=(\s*)(\w*)", "$1= $4") ConsoleWrite($s) FileDelete("test.ini") FileWrite("test.ini", $s) can you pleas explain me what is the different from the firs paragraph? i use: IniWrite ( "filename", "section", "key", "value" ) "If the facts don't fit the theory, change the facts." Albert Einstein Link to comment Share on other sites More sharing options...
GaRydelaMer Posted January 27, 2009 Share Posted January 27, 2009 Hi, for explain: you use : IniWrite ( "filename", "section", "key", "value" ) and you ask for write value Key= Value "=[space]value" but standart INIwrite function , you obtain Key=value I suggest to use Regexp for rewrite you're Inifile: $s = StringRegExpReplace($s, "(\w*)(\s*)=(\s*)(\w*)", "$1= $4") with this regexp you're file is completely rewriten for all key and value key= value And you ask again to write only one value Local $key = "verbose", $val = 5 IniWrite("test.ini", "control", $key, " " & $val) ; or IniWrite ( "filename", "section", "key", " " & "value" ) for me it's the better solution, for one value For more explain write you're code here Excuse me for my english Link to comment Share on other sites More sharing options...
shay Posted January 28, 2009 Author Share Posted January 28, 2009 Hi thank you for the explanation, its help me better understand it. i try both : Local $key = "verbose", $val = 5 IniWrite("test.ini", "control", $key, " " & $val) and IniWrite ( "filename", "section", "key", " " & "value" ) i`m getting section=[space]value i need section[space]=[space]value "If the facts don't fit the theory, change the facts." Albert Einstein Link to comment Share on other sites More sharing options...
BrettF Posted January 28, 2009 Share Posted January 28, 2009 (edited) Try this: ; here for one ; Why you noy use this ?? Local $key = "verbose", $val = 5 IniWrite("test.ini", "control", $key, " " & $val) ; here for all ;Or if you run more one time this reqexp change to: Local $s = FileRead("test.ini") $s = StringRegExpReplace($s, "(\w*)(\s*)=(\s*)(\w*)", "$1= $4") ;for specific keys, but in all section with the same key Local $key = "verbose" $s = StringRegExpReplace($s, "(" & $key & ")(\s*)=(\s*)(\w*)", "$1 = $4") ConsoleWrite($s) FileDelete("test.ini"); delete the file before rewriting because filewrite add line(s) at the end of file FileWrite("test.ini", $s) Thanks to GaRydelaMer for his StringRegExp... and of course the general answer Cheers, Brett Edited January 28, 2009 by BrettF Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Spiff59 Posted January 28, 2009 Share Posted January 28, 2009 (edited) You might get away with this: $key = "verbose" $val = 5 IniWrite("test.ini", "control", $key & Chr(160), " " & $val) Edited January 28, 2009 by Spiff59 Link to comment Share on other sites More sharing options...
shay Posted January 28, 2009 Author Share Posted January 28, 2009 You might get away with this:$key = "verbose" $val = 5 IniWrite("test.ini", "control", $key & Chr(160), " " & $val)YES!!! it work! thenk you allthis forum is great! "If the facts don't fit the theory, change the facts." Albert Einstein Link to comment Share on other sites More sharing options...
ForexGG Posted June 29, 2009 Share Posted June 29, 2009 YES!!! it work! thenk you all this forum is great! it's still not working. There is no space in front of the = sign. I need the same solution. $key = "verbose" $val = 5 IniWrite("test.ini", "control", $key & Chr(160), " " & $val) output: [control] verbose= 5 I need: [control] verbose = 5 someone please help! Link to comment Share on other sites More sharing options...
Aceguy Posted June 29, 2009 Share Posted June 29, 2009 $key = "verbose" $val = 5 IniWrite("test.ini", "control", $key & Chr(160), " " & $val) works for me! try deleting the inifile, and make it create a new one [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
Proph Posted June 29, 2009 Share Posted June 29, 2009 $key = "verbose" $val = 5 IniWrite("test.ini", "control", $key & Chr(160), " " & $val) works for me! try deleting the inifile, and make it create a new one I actually almost thought you guys came up with a simple method for this. I had been looking for a way to do this in the past but was not successful. I ended up having to code a custom func to fix it. I don't have that func anymore though. The problem with this method is that using Chr(160) will actually create a key with what looks like a regular space but is actually recognized as a different character in iniread. So whenever you need to iniread that key you have to make sure you also add the Chr(160) in your iniread command. For instance do this: IniWrite("test.ini", "control", $key & Chr(160), " " & $val) IniWrite("test.ini", "control", $key, " " & $val) You will notice it will write: [control] YourKey = YourValue YourKey= YourValue Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now