tezhihi Posted April 21, 2017 Share Posted April 21, 2017 #include <Array.au3> #include <File.au3> Global $a _FileReadToArray(@ScriptDir & "\aaaaaaaaaa.visf", $a) Local $c For $i = 1 to $a[0] if StringInStr($a[$i], '$200:') Then FileWrite(@ScriptDir & "\test.txt", $c) $c = $a[$i] & @CRLF EndIf Next Hi all, I have a file "aaaaaaaaaa.visf" and i want to get all $200: of this file to test file. But one problem appeared, all of $200: is 25 on source file but when I run this script the all of $200: appeared in "test.txt" file is 24. Please check and provide me how to fix this . aaaaaaaaaa.visf Link to comment Share on other sites More sharing options...
jguinch Posted April 21, 2017 Share Posted April 21, 2017 (edited) The first line ($c) is empty. change the order of your code, like this : $c = $a[$i] & @CRLF FileWrite(@ScriptDir & "\test.txt", $c) Edited April 21, 2017 by jguinch tezhihi 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 21, 2017 Moderators Share Posted April 21, 2017 @tezhihi not sure why you are writing $c to the output file, then declaring it in the next line. This works just fine for me, pulls all 25 instances, and even tells you the line it pulled them from: #include <Array.au3> #include <File.au3> Local $a _FileReadToArray(@UserProfileDir & "\downloads\aaaaaaaaaa.visf", $a) For $i = 1 To $a[0] If StringInStr($a[$i], "$200:") Then FileWriteLine(@DesktopDir & "\Test.txt", $a[$i] & " from line " & $i) Next tezhihi 1 "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...
tezhihi Posted April 21, 2017 Author Share Posted April 21, 2017 8 minutes ago, jguinch said: $c = $a[$i] & @CRLF FileWrite(@ScriptDir & "\test.txt", $c) Then first write is empty. Use this order : 8 minutes ago, JLogan3o13 said: @tezhihi not sure why you are writing $c to the output file, then declaring it in the next line. This works just fine for me, pulls all 25 instances, and even tells you the line it pulled them from: #include <Array.au3> #include <File.au3> Local $a _FileReadToArray(@UserProfileDir & "\downloads\aaaaaaaaaa.visf", $a) For $i = 1 To $a[0] If StringInStr($a[$i], "$200:") Then FileWriteLine(@DesktopDir & "\Test.txt", $a[$i] & " from line " & $i) Next Thanks you all. I already solved this problem Link to comment Share on other sites More sharing options...
tezhihi Posted April 22, 2017 Author Share Posted April 22, 2017 14 hours ago, JLogan3o13 said: @tezhihi not sure why you are writing $c to the output file, then declaring it in the next line. This works just fine for me, pulls all 25 instances, and even tells you the line it pulled them from: #include <Array.au3> #include <File.au3> Local $a _FileReadToArray(@UserProfileDir & "\downloads\aaaaaaaaaa.visf", $a) For $i = 1 To $a[0] If StringInStr($a[$i], "$200:") Then FileWriteLine(@DesktopDir & "\Test.txt", $a[$i] & " from line " & $i) Next Hi, Can I use _arrayfindall to find all $200: ? i try code below but it not run #include <Array.au3> #include <File.au3> Local $a, $b _FileReadToArray(@ScriptDir & '\aaaaaaaaaa.visf', $a) $b = _ArrayFindAll($a, '$200:$?#SID', 0, 0 ,0 ,0) _ArrayDisplay($b, "") Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 23, 2017 Moderators Share Posted April 23, 2017 If you are going to use _ArrayFindAll, you need to set the parameter for StringinStr search, like so: #include <Array.au3> #include <File.au3> Local $a, $b _FileReadToArray(@UserProfileDir & "\downloads\aaaaaaaaaa.visf", $a) $b = _ArrayFindAll($a, "$200", 1, Default, Default, 1) ;<--last param sets search to partial _ArrayDisplay($b, "Rows found") tezhihi 1 "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...
tezhihi Posted April 23, 2017 Author Share Posted April 23, 2017 4 hours ago, JLogan3o13 said: If you are going to use _ArrayFindAll, you need to set the parameter for StringinStr search, like so: #include <Array.au3> #include <File.au3> Local $a, $b _FileReadToArray(@UserProfileDir & "\downloads\aaaaaaaaaa.visf", $a) $b = _ArrayFindAll($a, "$200", 1, Default, Default, 1) ;<--last param sets search to partial _ArrayDisplay($b, "Rows found") Oh only find Rows . If I want to search value in Array, use _ArraySearch right? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 24, 2017 Moderators Share Posted April 24, 2017 @tezhihi you might try actually reading the help file on these two sections, you could probably find the answer to your question faster than you can post the question here. The help file shows you exactly what _ArraySearch returns vs. _ArrayFindAll (hint), and even has these nice little examples to show you when to use one over the other. tezhihi 1 "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...
kylomas Posted April 24, 2017 Share Posted April 24, 2017 (edited) tezhihi, Does this give you what you want? #include <Array.au3> #include <file.au3> Local $aRSLT = StringRegExp(FileRead(@ScriptDir & "\aaaaaaaaaa.visf"), '.*\$200.*', 3) If @error Then Exit MsgBox(0, 'Stringregexp error', 'Error = ' & @error) _FileWriteFromArray(@ScriptDir & '\$200.txt', $aRSLT) If @error Then Exit MsgBox(0, 'File write error', 'Error = ' & @error) ShellExecute(@ScriptDir & '\$200.txt') kylomas Edited April 24, 2017 by kylomas tezhihi 1 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...
tezhihi Posted April 25, 2017 Author Share Posted April 25, 2017 4 hours ago, kylomas said: tezhihi, Does this give you what you want? #include <Array.au3> #include <file.au3> Local $aRSLT = StringRegExp(FileRead(@ScriptDir & "\aaaaaaaaaa.visf"), '.*\$200.*', 3) If @error Then Exit MsgBox(0, 'Stringregexp error', 'Error = ' & @error) _FileWriteFromArray(@ScriptDir & '\$200.txt', $aRSLT) If @error Then Exit MsgBox(0, 'File write error', 'Error = ' & @error) ShellExecute(@ScriptDir & '\$200.txt') kylomas Thanks you so much. 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