Jump to content

Recommended Posts

Posted
#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

  • Moderators
Posted

@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

 

"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!

Posted
  On 4/21/2017 at 12:23 PM, jguinch said:
$c = $a[$i] & @CRLF
FileWrite(@ScriptDir & "\test.txt", $c)

Then first write is empty.

Use this order :

 

  On 4/21/2017 at 12:24 PM, 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

 

Expand  

Thanks you all. I already solved this problem

Expand  

 

Posted
  On 4/21/2017 at 12:24 PM, 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

 

Expand  

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, "")

 

  • Moderators
Posted

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")

 

"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!

Posted
  On 4/23/2017 at 7:50 PM, 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")

 

Expand  

Oh only find Rows :(. If I want to search value in Array, use _ArraySearch right?

  • Moderators
Posted

@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. ;)

"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!

Posted (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 by 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

Posted
  On 4/24/2017 at 7:14 PM, 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

Expand  

Thanks you so much.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...