Jump to content

Deleting a key in a .ini file.


Eru
 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
Share on other sites

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]

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...