Sign in to follow this  
Followers 0
Eru

Deleting a key in a .ini file.

4 posts in this topic

My inifile looks like this:

[ColorSet]

Color=XXX|YYY|ZZZ

XXX=111

YYY=222

ZZZ=333

I'm trying to use IniDelete to remove a specific saved set from the array, but all I'm getting it to do is remove the lower portion.

CSDel(YYY) yields:

[ColorSet]

Color=XXX|YYY|ZZZ

XXX=111

ZZZ=333

How can I get rid of the YYY in the variable list? I'm using a script to append to the end of it when I write, but can't seem to figure out how to search for what I want, then remove it. :)

Thank you for putting up with my newbie questions. m(:whistle:)m

Share this post


Link to post
Share on other sites



You'll have to re-write the value with IniWrite(.ini, colorset, color, xxx|zzz).


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Func IniDeleteSet($iniFilename, $sectionName, $keyName)
    $temp_string = StringReplace(FileRead($iniFilename, FileGetSize($iniFilename)), ($keyName & "=" & IniRead($iniFilename, $sectionName, $keyName, "") & @CRLF), "", 0, 1)

    FileOpen($iniFilename, 2)
    Local $temp_fileHandle = FileWrite($iniFilename, $temp_string)
    FileClose($temp_fileHandle)
EndFuncoÝ÷ Ø@ÈMay++y§H¶§*.Á©í¶¢YhÂ)àjëh×6$colorValue = IniRead("test.ini", "ColorSet", "Color", "")

$colorValue = StringReplace($colorValue, "YYY", "")
$colorValue = StringReplace($colorValue, "||", "|")

IniWrite("test.ini", "ColorSet", "Color", $colorValue)

Edited by Creative

"Everything is vague to a degree you do not realize till you have tried to make it precise." - Bertrand Russell [The Philosophy of Logical Atomism]

Share this post


Link to post
Share on other sites

Thanks guys. It always seems so easy when someone points it out. :whistle:

Share this post


Link to post
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
Sign in to follow this  
Followers 0