Hest Posted July 30, 2008 Share Posted July 30, 2008 (edited) I'm having a little problem converting a string to a variable.I'm reading an .ini file and have key1=value1 but in my script, I need to change "key1" into $key1How can I add that $ in the frontEdit: spelling Edited July 30, 2008 by Hest Software:Model Train Calculator (Screen)Autoit3 beginner! Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 30, 2008 Share Posted July 30, 2008 Hi, just FileRead and then StringReplace FileWrite. Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Hest Posted July 30, 2008 Author Share Posted July 30, 2008 I have tried stringreplace, but I cant get it working. Whats wrong in this $string is key1 $string = StringReplace($var[$i][0], start, "$") Software:Model Train Calculator (Screen)Autoit3 beginner! Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 30, 2008 Share Posted July 30, 2008 I have tried stringreplace, but I cant get it working. Whats wrong in this $string is key1 $string = StringReplace($var[$i][0], start, "$") Hi, I cannot follow you. Start needs quotes or should it be a variable? What error? Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Hest Posted July 30, 2008 Author Share Posted July 30, 2008 (edited) The qoutes around start got rid of the error, so I'm half way there now but I'm not getting the $ in front of key1 When I read my .ini file, I have $var[1][0] and $var[1][1] from the first line, they are: "key1" and "value1" from line one, "key2" and "value2" from line two and so on. What I want to do now, is make the string "key1" into $key1 = "value1" and the next $key2 = "value2" and so on. Here is the code Im using to read everything $var = IniReadSection("lang.ini", "language") If @error Then MsgBox(4096, "", "ini file does not exist.") Else for $i = 1 to $var[0][0] $string = StringReplace($var[$i][0], "start", "$") next endif Im not sure I have explained it right. What I need is just to turn every key from the .ini into a variable with the value without using $ in the .ini Edited July 30, 2008 by Hest Software:Model Train Calculator (Screen)Autoit3 beginner! Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 30, 2008 Share Posted July 30, 2008 Hi, you can try this: Global $content = FileRead(@ScriptDir & '\section.ini') Global $re = StringRegExp($content, '\w+(?=\=)', 3) For $i = 0 To UBound($re) -1 $content = StringReplace($content, $re[$i], '$' & $re[$i]) Next FileWrite(FileOpen(@ScriptDir & '\section.ini', 2), $content) Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
YellowLab Posted July 30, 2008 Share Posted July 30, 2008 (edited) I think one function you may want to look at is "Assign." Here are the steps I think you want to take: 1) read the section of the INI file. This results in a two dimensional array: $array[n][0] is the KEY name, $array[n][1] is the value. 2) loop through the array and Assign($array[n][0], $array[n][1]) Outline Code looks like this (not tested): $arSections = IniReadSections("MYINIFILE.INI") For $nSections = 1 to Ubound($arSections)-1 $arINI = IniReadSeciton("MYINIFILE.INI",$arSections[$nSections]) For $nCount = 1 to Ubound($arINI) - 1 Assign($arINI[$nCount][0],$arINI([$ncount][1])) Next Next This assumes that there are no keys with the same name in different sections. If this is the case, the one in the latest section will over write earlier ones. Hope this helps. Bob Edited July 30, 2008 by YellowLab You can't see a rainbow without first experiencing the rain. Link to comment Share on other sites More sharing options...
Hest Posted July 30, 2008 Author Share Posted July 30, 2008 Thx to both of you. I will try to change my script and see if it works Software:Model Train Calculator (Screen)Autoit3 beginner! 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