neo van matix Posted February 12, 2011 Share Posted February 12, 2011 Hello, i'm writing a little script, that parses an configuration file. This is the *.ini-File (from prism): [Parameters] id=worldclient@xxx name=WorldClient uri=http://xxx:3000/worldclient.dll?View=Main&User=EMAILADRESSE&Password=PASSWORT icon=favicon status=yes location=no sidebar=no navigation=no trayicon=yes Okay, now.. i wrote a script, that splits this File by the ending @CRLF into an array; each $array[x] is one line of the ini-File. Then, i split each line, if the script finds an "=". That works perfectly - a little bit to perfect. Line 4 - the uri-parameters... The Code of the ReadWebappIni: Func ReadWebappIni() $file = FileOpen("c:\prism\_packages\worldclient.webapp-source\WebApp.ini", 0) If $file = -1 Then MsgBox(0, "Fehler", "Konnte c:\prism\_packages\worldclient.webapp-source\WebApp.ini nicht öffnen!") Else $configfile = FileRead($file) $configfile = StringSplit($configfile, @CRLF, 1) For $i = 2 to $configfile[0] $configfile_var = _StringExplode($configfile[$i], "=", 0) _ArrayDisplay($configfile_var) Switch $configfile_var[0] Case "id" GUICtrlSetData($input_id, $configfile_var[1]) Case "name" GUICtrlSetData($input_name, $configfile_var[1]) Case "uri" GUICtrlSetData($input_uri, $configfile_var[1]) Case "icon" GUICtrlSetData($input_icon, $configfile_var[1]) Case "status" IF $configfile_var[1] = "yes" Then GUICtrlSetState($checkbox_statusbar, $GUI_CHECKED) Case "location" IF $configfile_var[1] = "yes" Then GUICtrlSetState($checkbox_location, $GUI_CHECKED) Case "navigation" IF $configfile_var[1] = "yes" Then GUICtrlSetState($checkbox_navigation, $GUI_CHECKED) Case "trayicon" IF $configfile_var[1] = "yes" Then GUICtrlSetState($checkbox_trayicon, $GUI_CHECKED) EndSwitch Next EndIf EndFunc What could i do? Is there any function, that works like... "Split by the first occurance of = the string into two parts; first part all chars left by =; second part all chars right by =" ? Maybe with a regex? thanks for help! Attention! English noob ^^ Link to comment Share on other sites More sharing options...
BrewManNH Posted February 12, 2011 Share Posted February 12, 2011 Try using the Iniread functions instead, it's a lot easier than what you're doing. You also might want to use the IniReadSection function which will put all the keys/values into an array. One line will do it all. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
John Posted February 12, 2011 Share Posted February 12, 2011 I would use StringInStr() to get the location of "?", then StringTrimLeft() to get the string to the right side the "?". $string="aaaa?a=b&b=c" $string=StringTrimLeft($string,StringInStr($string,"?")) MsgBox(0,"",$string) Then you can StringSplit() what remains using "=" as a delimiter. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 12, 2011 Share Posted February 12, 2011 (edited) Here's how to do it the short way: #include <Array.au3> $File = "c:\prism\_packages\worldclient.webapp-source\WebApp.ini" $Array = IniReadSection($File, "Parameters") _ArrayDisplay($Array) Edited February 12, 2011 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
neo van matix Posted February 12, 2011 Author Share Posted February 12, 2011 Here's how to do it the short way: #include <Array.au3> $File = "c:\prism\_packages\worldclient.webapp-source\WebApp.ini" $Array = IniReadSection($File, "Parameters") _ArrayDisplay($Array) omfg -.- It's really nothing more... and i tried it the other way for many hours.. -.- Thanks! Attention! English noob ^^ Link to comment Share on other sites More sharing options...
BrewManNH Posted February 12, 2011 Share Posted February 12, 2011 It's fortunate that the file you were trying to read from was in the .ini format which makes it soooo much easier to parse it. Of course if the file wasn't in the .ini format, you could always convert it to an .ini file by reading in the first file, and then using IniWriteSection to write the text to a temporary .ini file, and reading it in again using the scriptlet I gave you, and then deleting the temp ini file. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
John Posted February 13, 2011 Share Posted February 13, 2011 Many scripts that I run uncompiled I will wrap the ini settings in quote tags and use the script itself as the settings file. 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