Oldschool Posted December 20, 2007 Share Posted December 20, 2007 I'm trying to read of prices from lines that look like this: Item Price [$16.96].#92378654906# Dim $aRecords If Not _FileReadToArray("text.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf For $y = 1614 to $aRecords[0] ;Msgbox(0,'Record:' & $x, $aRecords[$x]) If StringInStr($aRecords[$y], "$") Then Local $price = StringRegExp($aRecords[$y],"(?i)e"&Chr(32)&Chr(91)&"$(.*)"&Chr(93), 0) MsgBox(0, "", $price, 1) ;<<===Item Price ;ExitLoop EndIf Next I get no error, MsgBox returns zero. It does not like the brackets [] I suppose. How do I fix this please? Link to comment Share on other sites More sharing options...
Kerros Posted December 20, 2007 Share Posted December 20, 2007 (edited) it's not perfect, but should point you in the right direction. Local $price = StringRegExp($aRecords[$y],"(.*[$.*])", 0) Maybe someone with with better regex will give you better example Edited December 20, 2007 by Kerros Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance. Link to comment Share on other sites More sharing options...
Oldschool Posted December 20, 2007 Author Share Posted December 20, 2007 it's not perfect, but should point you in the right direction. Local $price = StringRegExp($aRecords[$y],"(.*[$.*])", 0) Maybe someone with with better regex will give you better example The above does not work.. If slightly modified it returns the whole string: Local $price = StringRegExp($aRecords[$y],"(.*[$.*])", 3) MsgBox(0, "", $price[0], 1) I need to grab the digits only.... Link to comment Share on other sites More sharing options...
Kerros Posted December 20, 2007 Share Posted December 20, 2007 (edited) Well this is going to return an array of everything after the $ upto the trailing bracket. Local $price = StringRegExp($aRecords[$y],"(\$\d{1,}.\d{2,})", 3) That should work. messy, but should work. Edited December 20, 2007 by Kerros Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance. Link to comment Share on other sites More sharing options...
Oldschool Posted December 20, 2007 Author Share Posted December 20, 2007 Well this is going to return an array of everything after the $ upto the trailing bracket. Local $price = StringRegExp($aRecords[$y],"(\$\d{1,}.\d{2,})", 3) That should work. messy, but should work. Thanks, I'll test it out in a sec... I got it working with the StringSplit instead for now. For $y = $aRecords[0] - 40 to $aRecords[0] If StringInStr($aRecords[$y], "$") Then Local $var = StringSplit($aRecords[$y], Chr(91) & Chr(36), 1) Local $var1 = StringSplit($var[2], Chr(93), 1) MsgBox(0, "", $var1[1]) EndIf Next Link to comment Share on other sites More sharing options...
Xenobiologist Posted December 20, 2007 Share Posted December 20, 2007 Hi, (?<=\[\$)\d*\.\d*(?=\]) So long, 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...
Moderators SmOke_N Posted December 20, 2007 Moderators Share Posted December 20, 2007 Hi, (?<=\[\$)\d*\.\d*(?=\]) So long, MegaThat's an interesting approach... here's another:#include <array.au3> $sString = "Item Price [$16.96].#92378654906#" $aSRE = StringRegExp($sString, "\[\$([\d,\.]+)\]", 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...
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