Sign in to follow this  
Followers 0
richietheprogrammer

Search Array- Find next 2 fileds?

8 posts in this topic

#1 ·  Posted (edited)

I have a csv file that I want to make an array to search it using_FileReadToArray (Thanks to this thread: ). But, when I want to search it to find a field, once I find the field (location), I then want to pull the next 2 fields after it. So far I have:

_FileReadToArray("sample.csv",$csv)
$record=StringSplit($csv[$i],",",2)
For $x = 1 to $record[0]
    $location = StringInStr($record, $searched)
    msgbox(0,$location,$location)
Next

And it is not working ;)

Any help would be greatly apreciated :)!!

Edited by richietheprogrammer

Share this post


Link to post
Share on other sites



Explain to yourself what is $i in

$record=StringSplit($csv[$i],",",2)

Hint: you aren't actually searching the array right now.

Then lookup what 2 means as third parameter to StringSplit. It doesn't do what you need.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Explain to yourself what is $i in

$record=StringSplit($csv[$i],",",2)

Hint: you aren't actually searching the array right now.

Then lookup what 2 means as third parameter to StringSplit. It doesn't do what you need.

Thanks for your help. I did try all parameters. What should the code look like? Note that because its a csv, its not like searching a regular array. so I need to read the next 2 cells.

Share this post


Link to post
Share on other sites

You exhibit little knowledge on arrays.

For example, in this line:

$record=StringSplit($csv[$i],",",2)

$i should contain an integer representing the index at which you are wanting to split.

It would help to display a bit of text that is contained within your file, in addition to the return values you would like to see from that text.


[center][/center]

Share this post


Link to post
Share on other sites

First of all, you have a presumably multiline .csv file. Reading it with _FileReadToArray() leaves you with an array of lines, each of which is a separate line in the input .CSV

OK, now which line in the CSV do you need information from? That would be searching in the array. Once you've found the relevant line(s) or decided that your processing has to be applied to every line (???) then you can split the line to be processed (yes, with the comma separator) and lookup the field you're after. Knowing its index will help you access next 2 fields.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

First of all, you have a presumably multiline .csv file. Reading it with _FileReadToArray() leaves you with an array of lines, each of which is a separate line in the input .CSV

OK, now which line in the CSV do you need information from? That would be searching in the array. Once you've found the relevant line(s) or decided that your processing has to be applied to every line (???) then you can split the line to be processed (yes, with the comma separator) and lookup the field you're after. Knowing its index will help you access next 2 fields.

I understand the logic, basically once it finds the string, I will read the [1] and [2], which will work since the number that I am searching will always be in the first column. I am having issues with the syntax, so if you could help with that, I would appreciate it :)!

Share this post


Link to post
Share on other sites

You exhibit little knowledge on arrays.

For example, in this line:

$record=StringSplit($csv[$i],",",2)

$i should contain an integer representing the index at which you are wanting to split.

It would help to display a bit of text that is contained within your file, in addition to the return values you would like to see from that text.

Thanks for this. basically my csv has

1 2 3

4 5 6

7 8 9

and I will want to search for things in the first column. So if i search for "4", it should return (as 2 separate variables) 5 and 6.

Share this post


Link to post
Share on other sites

Thanks everybody, I got it :)

#include <File.au3>
#Include <Array.au3>
$csv=0
$x=0
_FileReadToArray("file.csv",$csv)
$searched= inputbox("","Enter")
$searches= _arraysearch($csv,$searched,0,0,0,1,1,0)
msgbox(0,"",$searches)
$record1=StringSplit($csv[$searches],",",2)
$record2=StringSplit($csv[$searches],",",2)
msgbox(0,"",$record1[1])
msgbox(0,"",$record2[2])

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
Sign in to follow this  
Followers 0