xcaliber13 Posted June 22, 2016 Share Posted June 22, 2016 Hey Everyone, Can you get me going in the right direction please. Here is what I am trying to do: I have a large text file that I want to find a string. <-- No problem with that part Once I find that string which is always at the beginning of the line Example string ABC: After the found string (ABC:) there are sets of 5 characters/Numbers separated by commas. Example: J0203, 77955 So the line looks like this: ABC: G0203, 77955 Some lines have just one set with no trailing comma and some have more than one set. I want to count the sets into a variable. Would I do this with StringRegExp or some other way? Thank you Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 22, 2016 Moderators Share Posted June 22, 2016 @xcaliber13 something like this perhaps? #include <File.au3> #include <MsgBoxConstants.au3> Local $aText = FileReadToArray(@DesktopDir & "\Test1.txt") For $i = 0 To UBound($aText) - 1 $aTemp = StringSplit($aText[$i], ",") MsgBox($MB_OK, "", "Found " & $aTemp[0] & " data sets in line " & $i + 1) Next Works on a text file like this: ABC: G0203, 77955 ABC: G0203, 77955, 42358, 65989, 12115 ABC: G0203, 77955, 42358, 65989, 12115 ABC: G0203, 77955, 42358, 65989, 12115 ABC: G0203, 77955, 65989, 12115 ABC: G0203, 77955, 42358, 65989, 12115 ABC: G0203, 77955, 42358, 12115 ABC: G0203, 77955, 42358, 65989, 12115 ABC: G0203, 77955, 42358, 65989, 12115 ABC: G0203, 77955, 42358, 65989, 12115 ABC: G0203, 77955, 42358, 65989, 12115 ABC: G0203 ABC: G0203, 77955, 42358, 65989, 12115 ABC: G0203, 77955, 42358, 65989, 12115 ABC: G0203, 77955, ABC: G0203, 77955, 42358, 65989, 12115 ABC: G0203, 77955, 42358, 65989 ABC: G0203, 77955, 42358, 65989, 12115 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
mikell Posted June 22, 2016 Share Posted June 22, 2016 (edited) Not sure I understood, maybe this ? #Include <Array.au3> $string = "ABC:" Local $sText = FileRead(@DesktopDir & "\Test1.txt") $a = StringRegExp($sText, '(?m)(?<=^' & $string & '\h|\w{5},\h)\h*(\w{5})', 3) ;_ArrayDisplay($a) Msgbox(0,"", UBound($a) & " sets in all the lines " & $string) Edited June 22, 2016 by mikell Link to comment Share on other sites More sharing options...
kylomas Posted June 23, 2016 Share Posted June 23, 2016 xcaliber13, Another way (similar to JL's)... #Include <Array.au3> local $aText = stringregexp(fileread(@DesktopDir & "\Test.txt"),'.*\R',3) local $aFinal[ubound($aText)][2] for $1 = 0 to ubound($aText) - 1 StringRegExpReplace($aText[$1],'\w{5}','') $aFinal[$1][0] = @extended $aFinal[$1][1] = $aText[$1] Next _arraydisplay($aFinal) For a definitive answer you should post real data. It is unlikely that the sample we're using is representative. Also, as you can see, JL and I interpreted your task one way and mikell another. Please define your requirements further. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
xcaliber13 Posted June 23, 2016 Author Share Posted June 23, 2016 JLogan3o13, MikeII, kylomas, Thank you all for the replies. Between all of your examples I was able to do what I need to. Get the total count of all the sets. Just another example why AutoIt is so powerful. The Autoit forums are the best there is as far as actually helping with coding problems. You guys are the best. Again thank you to all 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