Jump to content
tezhihi

Write data from file

Recommended Posts

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

Share this post


Link to post
Share on other sites
jguinch

 

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
  • Like 1

Share this post


Link to post
Share on other sites
JLogan3o13

@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

 

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
tezhihi
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

 

Share this post


Link to post
Share on other sites
tezhihi
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, "")

 

Share this post


Link to post
Share on other sites
JLogan3o13

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

 

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
tezhihi
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?

Share this post


Link to post
Share on other sites
JLogan3o13

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

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
kylomas

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
  • Like 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

Share this post


Link to post
Share on other sites
tezhihi
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.

Share this post


Link to post
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

×