Jump to content

Write data from file


Recommended Posts

#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

 

The first line ($c) is empty. change the order of your code, like this :

$c = $a[$i] & @CRLF
FileWrite(@ScriptDir & "\test.txt", $c)

 

 

Edited by jguinch
Link to comment
Share on other sites

  • Moderators

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

Link to comment
Share on other sites

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

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

  • Moderators

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!

Link to comment
Share on other sites

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

  • Moderators

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

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