LoneWolf_2106 Posted July 28, 2017 Posted July 28, 2017 Hi, i have created a function which takes in Input an Array with a file Content(stored in an Array) and a string to search. I have several files to scan and i am using the same Array to store my results.(which i have to print in a second stage) I have created a global Counter out of the function to store the "Offset" and it should append the results of the successive files at the last Position of the Array. But of course if i add the increment within the for Loop, the index will be spoiled because it will be doubled. Func FileSearch($file_content_array, $stringToSearch) $j=0 For $i = 0 To UBound($file_content_array) - 1 $search_result=StringInStr($file_content_array[$i],$stringToSearch) If $search_result<>0 Then ReDim $searchResultArray[UBound($searchResultArray) + 1] $j+=$counter $searchResultArray [$j] = $file_content_array[$i] $j+=1 $counter+=1 EndIf Next Return $searchResultArray EndFunc May someone give me an advice to solve the issue? Thanks in advance
Danp2 Posted July 28, 2017 Posted July 28, 2017 Not sure that I understand the problem. However, this line looks out of place $j+=$counter Why not set $j=$counter before the loop starts and just eliminate that line? Latest Webdriver UDF Release Webdriver Wiki FAQs
Trong Posted July 28, 2017 Posted July 28, 2017 Try this function: Func _ArraySearchToArray($sArrayToSearch, $stringToSearch, $nStart = 0) Local $rList, $rArray = UBound($sArrayToSearch) - 1 If $nStart > $rArray Or $nStart < 0 Then Return SetError(1, 0, "") For $i = $nStart To $rArray If StringInStr($sArrayToSearch[$i], $stringToSearch) Then $rList &= $sArrayToSearch[$i] & @CR Next If $rList == "" Then Return SetError(2, 0, "") $rArray = StringSplit($rList, @CR, $nStart = 0 ? 2 : 0) Return $rArray EndFunc ;==>_ArraySearchToArray - Dao Van Trong - TRONG.WIN Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal
jdelaney Posted July 28, 2017 Posted July 28, 2017 (edited) If $search_result Then ReDim $searchResultArray[UBound($searchResultArray) + 1] $searchResultArray[UBound($searchResultArray)-1] = $file_content_array[$i] EndIf A little simplified Edited July 28, 2017 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Malkey Posted July 28, 2017 Posted July 28, 2017 Where jdelaney is going you don't need counters. ditto. Func FileSearch($file_content_array, $stringToSearch) For $i = 0 To UBound($file_content_array) - 1 $search_result = StringInStr($file_content_array[$i], $stringToSearch) If $search_result Then ; Zero is false. Anything that is not zero is true. ReDim $searchResultArray[UBound($searchResultArray) + 1] $searchResultArray[UBound($searchResultArray) - 1] = $file_content_array[$i] ; "UBound($searchResultArray) - 1" is the last index number of the array, $searchResultArray. EndIf Next Return $searchResultArray EndFunc ;==>FileSearch
LoneWolf_2106 Posted August 14, 2017 Author Posted August 14, 2017 Hi, i haven't tried your solutions yet, because i have restructered the code. As soon as i have time, i will try them and give you a feedback. Many thanks for your support.
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