AustrianOak Posted June 14, 2008 Share Posted June 14, 2008 (edited) I am trying to delete a certain value in my ini file and I tried IniDelete() and then read throught the helpfile to find out that IniDelete() can delete values but it looks to me as if it deletes all or none. Is there some way I can delete a certain value in a key? Maybe I'm confused, maybe I severely misread the helpfile. Please someone correct me. Edited June 14, 2008 by nowagain Link to comment Share on other sites More sharing options...
rudi Posted June 14, 2008 Share Posted June 14, 2008 I am trying to delete a certain value in my ini file and I tried IniDelete() and then read throught the helpfile to find out that IniDelete() can delete values but it looks to me as if it deletes all or none.Is there some way I can delete a certain value in a key?Maybe I'm confused, maybe I severely misread the helpfile.Please someone correct me.I'm not sure I get what you are asking for.Maybe you could give us an example, how your INI looks like originally, and how it shall look like finally?Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
AustrianOak Posted June 14, 2008 Author Share Posted June 14, 2008 (edited) here's an example of what it looks like: [section] key1=value1;value2 I'm running through a for loop in my program and depending on certain results it will delete a specific value in a key. Let's say I wanted to delete value2 above. What I wahnt it to look like finally is like this: [section] key1=value1 How? IniDelete() doesn't look like it can do it from what I read in the helpfile. Edited June 14, 2008 by nowagain Link to comment Share on other sites More sharing options...
ResNullius Posted June 14, 2008 Share Posted June 14, 2008 here's an example of what it looks like: [section] key1=value1;value2 I'm running through a for loop in my program and depending on certain results it will delete a specific value in a key. Let's say I wanted to delete value2 above. What I wahnt it to look like finally is like this: [section] key1=value1 How? IniDelete() doesn't look like it can do it from what I read in the helpfile.A standard Ini file wouldn't quite be setup that way for deleting values from. It would be more like [section] key1=value1 key2=value2 Which IniDelete() can easily handle. Do you absolutely have to have the format with more than one value in a single key as you posted? If so, what you want is doable, it just needs some custom coding with IniRead(), StringReplace(), & IniWrite() (probably)... Link to comment Share on other sites More sharing options...
AustrianOak Posted June 14, 2008 Author Share Posted June 14, 2008 Ok, but how do I go about doing that? I have no idea how to implement iniwrite and iniread to delete a specific value... Link to comment Share on other sites More sharing options...
ProgAndy Posted June 14, 2008 Share Posted June 14, 2008 First you have touse IniRead, Then StringSplit Remove the Value from the Array, use _ArrayToString And Write it back to the ini *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Kiti Posted June 14, 2008 Share Posted June 14, 2008 (edited) here's an example of what it looks like: [section] key1=value1;value2 I'm running through a for loop in my program and depending on certain results it will delete a specific value in a key. Let's say I wanted to delete value2 above. What I wahnt it to look like finally is like this: [section] key1=value1 How? IniDelete() doesn't look like it can do it from what I read in the helpfile.Try this: $keys = "value1;value2" If .... Then $key = StringTrimRight($keys, 7) Else $key = StringTrimLeft($keys, 7) EndIf If the lenght of $keys is variable, then you should use StringSplit, as ProgAndy said: $keys ="Value1,Value2,Value3,Value4" $key = StringSplit($keys, ",") This would create a one dimensional array. Now, $key[1] = "Value1", $Keys[3]="Value3". I'm not sure if this is helpful to this specific situation, but it's a good thing to know: When using a for loop and an x-dimensional array, you can do something like this: for $i=1 to $keys[0] ;do something with $keys[$i] Next This will do something to each value of an array. Note: $keys[0] is the dimension of the array, how many values it has stored in. Sorry if you already knew this things. Edited June 14, 2008 by Kiti Think outside the box.My Cool Lego Technic Website -- see walking bipeds and much more!My YouTube account -- see cool physics experimentsMy scripts:Minesweeper bot: Solves advanced level in 1 second (no registry edit), very improved GUI, 4 solving stylesCan't go to the toilet because of your kids closing your unsaved important work? - Make a specific window uncloseableCock Shooter Bot -- 30 headshots out of 30 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 14, 2008 Moderators Share Posted June 14, 2008 _IniDeleteValue("SomeIni.ini", "Section", "Key1", "myvaluetoreplace", ",") Func _IniDeleteValue($sIni, $sSection, $sKey, $sFind, $sDelim = "", $vCaseSensitive = False) Local $sRead = IniRead($sIni, $sSection, $sKey, "") If $sRead = "" Then Return SetError(1, 0, 0) Local $vCase = "(?i)" If $vCaseSensitive Then $vCase = "" $sRead = StringRegExpReplace($sRead, "(?s)" & $vCase & _ $sDelim & $sFind & "$|" & $sFind & $sDelim, "") Return IniWrite($sIni, $sSection, $sKey, $sRead) EndFunc 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 More sharing options...
AustrianOak Posted June 14, 2008 Author Share Posted June 14, 2008 Thank you Smoke_N. and thank you all others who helped me. Problem resolved. 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