Jump to content

help with IniWrite


shay
 Share

Recommended Posts

Hi

i try to add new "key+value" to INI file

i need to add verbose = 5

using the command : IniWrite ( "test.ini", "control", "verbose", "5" )

i get line that look like that: verbose=5

but 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

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

that ok my English is no so good to :lmao:

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

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 by GaRydelaMer
Link to comment
Share on other sites

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

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

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

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 by BrettF
Link to comment
Share on other sites

You might get away with this:

$key = "verbose"
$val = 5
IniWrite("test.ini", "control", $key & Chr(160), " " & $val)
YES!!! it work! :)

thenk you all

this forum is great! :lmao:

"If the facts don't fit the theory, change the facts." Albert Einstein

Link to comment
Share on other sites

  • 5 months later...

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

$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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...