AustrianOak Posted June 11, 2008 Share Posted June 11, 2008 (edited) I have a string in my ini file that looks like this: text|123;text|456;text|789 and I am looking for a way only to extract the string "text" from the ini file. I tried something like this: $var = INIRead(@ScriptDir & "\temp.ini, "section", "key", "") $split = StringSplit($var, ";"); i first split by semi-colon $split2 = StringSplit($split[1], "|"); then i split by the "|" characters For $i = 1 To $split2[0] MsgBox(0, "", $split2[$i]) msgbox() only returns the first text in the ini, it doesn't return all three.. where did i go wrong? Edited June 11, 2008 by nowagain Link to comment Share on other sites More sharing options...
James Posted June 11, 2008 Share Posted June 11, 2008 Try StringRegExp() atetester132 1 Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 11, 2008 Moderators Share Posted June 11, 2008 #include <array.au3> $var = "text|123;text|456;text|789" $aSRE = StringRegExp($var, "(?s)(?m:^|;)(.+?)\|", 3) _ArrayDisplay($aSRE) 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...
weaponx Posted June 11, 2008 Share Posted June 11, 2008 StringSplitRegExp Link to comment Share on other sites More sharing options...
AustrianOak Posted June 11, 2008 Author Share Posted June 11, 2008 what if my ini starts out in a different format than what i told you. it starts out usually in this format: key=text;text;text how would stringregexp() need to be changed? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 11, 2008 Moderators Share Posted June 11, 2008 what if my ini starts out in a different format than what i told you.it starts out usually in this format:key=text;text;texthow would stringregexp() need to be changed?Use weaponx's version or do some experiments on your own... Once you've exhausted yourself on trying to figure it out, post all that you've tried to receive assistance with RegExp's. 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...
James Posted June 11, 2008 Share Posted June 11, 2008 IniRead() and StringSplit() Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted June 11, 2008 Share Posted June 11, 2008 what if my ini starts out in a different format than what i told you.it starts out usually in this format:key=text;text;texthow would stringregexp() need to be changed?If you are using IniRead then "key=" will no longer be part of your string, it will only return "text;text;text".... Link to comment Share on other sites More sharing options...
James Posted June 11, 2008 Share Posted June 11, 2008 If you are using IniRead then "key=" will no longer be part of your string, it will only return "text;text;text"....Then you only need to StringSplit($MyIni[1][1], ";") Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Xenobiologist Posted June 11, 2008 Share Posted June 11, 2008 Do you really mean only text, or are there other word than just text? 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...
martin Posted June 11, 2008 Share Posted June 11, 2008 I have a string in my ini file that looks like this: text|123;text|456;text|789 and I am looking for a way only to extract the string "text" from the ini file. I tried something like this: $var = INIRead(@ScriptDir & "\temp.ini, "section", "key", "") $split = StringSplit($var, ";"); i first split by semi-colon $split2 = StringSplit($split[1], "|"); then i split by the "|" characters For $i = 1 To $split2[0] MsgBox(0, "", $split2[$i]) msgbox() only returns the first text in the ini, it doesn't return all three.. where did i go wrong?A bit late but I notice that no one actually answered your question. You went wrong here For $i = 1 To $split2[0] It should have been For $i = 1 To $split[0] Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
AustrianOak Posted June 11, 2008 Author Share Posted June 11, 2008 there are other words than just text. its like: value1;value4 if thats what you were asking, its not the same exact string called "text" Link to comment Share on other sites More sharing options...
AustrianOak Posted June 11, 2008 Author Share Posted June 11, 2008 (edited) It should have been For $i = 1 To $split[0] But then how would it have split by "|" this if it wasn't $split2[0]? Edit: I think the easiest thing to do is to go with weaponx's way. anyway...im getting some sleep, been up 24 hours... Edited June 11, 2008 by nowagain Link to comment Share on other sites More sharing options...
Xenobiologist Posted June 11, 2008 Share Posted June 11, 2008 #include <array.au3> $var = "text|123;text|456;text|789" $aSRE = StringRegExp($var, "\w+", 3) _ArrayDisplay($aSRE) ;or $aSRE = StringRegExp($var, "[^\|;0-9]+", 3) _ArrayDisplay($aSRE) 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...
crashdemons Posted June 11, 2008 Share Posted June 11, 2008 (edited) process('text|123;text|456;text|789') Func process($string) $delim1=StringSplit($string,';') $max=UBound($delim1)-1 For $i=1 To $max $delim2=StringSplit($delim1[$i],'|') $text=$delim2[1] $number=$delim2[2] ;;Do Whatever Here MsgBox(0,'','Entry #'&$i&@CRLF&'Text: '&$text&@CRLF&'Number: '&$number) ;;Do Whatever Here Next EndFunc Edited June 11, 2008 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
AustrianOak Posted June 12, 2008 Author Share Posted June 12, 2008 @crashdemons: look at this: process('text|123;text|456;text|789') Func process($string) $delim1=StringSplit($string,';') $max=UBound($delim1)-1 For $i=1 To $max $delim2=StringSplit($delim1[$i],'|') $text=$delim2[1] $number=$delim2[2] ;;Do Whatever Here MsgBox(0,'','Entry #'&$i&@CRLF&'Text: '&$text&@CRLF&'Number: '&$number) ;;Do Whatever Here Next EndFunc msgbox(0, "", $text) its gives me an error that $text is "undeclared" when i put it in the msgbox()? what if i only want that function to return just $text so i can used it "outside" the function. what do i have to do?... Link to comment Share on other sites More sharing options...
weaponx Posted June 12, 2008 Share Posted June 12, 2008 @crashdemons: look at this: process('text|123;text|456;text|789') Func process($string) $delim1=StringSplit($string,';') $max=UBound($delim1)-1 For $i=1 To $max $delim2=StringSplit($delim1[$i],'|') $text=$delim2[1] $number=$delim2[2] ;;Do Whatever Here MsgBox(0,'','Entry #'&$i&@CRLF&'Text: '&$text&@CRLF&'Number: '&$number) ;;Do Whatever Here Next EndFunc msgbox(0, "", $text) its gives me an error that $text is "undeclared" when i put it in the msgbox()? what if i only want that function to return just $text so i can used it "outside" the function. what do i have to do?... The scope of $text is limited to that function, move your call to msgbox... Link to comment Share on other sites More sharing options...
AustrianOak Posted June 12, 2008 Author Share Posted June 12, 2008 I dont understand what you mean by move my call. Link to comment Share on other sites More sharing options...
weaponx Posted June 12, 2008 Share Posted June 12, 2008 I dont understand what you mean by move my call.You need to learn about variable scope first:http://www.autoitscript.com/autoit3/docs/i...g_variables.htmVariables defined within a function are considered local to said function (unless declared Global), meaning the variable does not exist outside the extents of Func...EndFunc. Link to comment Share on other sites More sharing options...
AustrianOak Posted June 12, 2008 Author Share Posted June 12, 2008 (edited) Well having that said then all I should have to do is add Global for $text in the process()So I now I have no clue as how to use the $text variable... Edited June 12, 2008 by nowagain 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