stojko22 Posted August 24, 2017 Posted August 24, 2017 Hi, i'm trying to read a big ini file so ini read don't work for me. Now i use file read but i getting back only a numbers not a results with string that match search term, how i can fix that ? #include <FileConstants.au3> $file = FileOpen("test.ini") ; open file $bb = FileRead($file) ; read file If @error Then ConsoleWrite("Error : " & @error & @CRLF) Else $aa = StringInStr($bb, "Blode") ; find in ini file If @error Then ConsoleWrite("Error : " & @error & @CRLF) Else ConsoleWrite($aa) ; returns 6240146 EndIf EndIf
Danp2 Posted August 24, 2017 Posted August 24, 2017 Quote StringInStr Checks if a string contains a given substring. StringInStr ( "string", "substring" [, casesense = 0 [, occurrence = 1 [, start = 1 [, count]]]] ) Parameters string The string to evaluate. substring The substring to search for. casesense [optional] Flag to indicate if the operations should be case sensitive. $STR_NOCASESENSE (0) = not case sensitive, using the user's locale (default) $STR_CASESENSE (1) = case sensitive $STR_NOCASESENSEBASIC (2) = not case sensitive, using a basic/faster comparison Constants are defined in StringConstants.au3. occurrence [optional] Which occurrence of the substring to find in the string. Use a negative occurrence to search from the right side. The default value is 1 (finds first occurrence). start [optional] The starting position of the search. count [optional] The number of characters to search. This effectively limits the search to a portion of the full string. See remarks. Return Value Success: the position of the substring. StringInStr returned the position where the substring was found, so returning a number is a good thing. ;-) Latest Webdriver UDF Release Webdriver Wiki FAQs
Floops Posted August 24, 2017 Posted August 24, 2017 Something like this should work $file = FileOpen("test.ini") ; open file $i = 0 Do $i += 1 $bb = FileReadLine($file, $i) $iError = @error If StringInStr($bb, "Blode") Then ConsoleWrite("Substring found in line: " & $i & " | Text: " & $bb & @CRLF) Until $iError = -1 FileClose($file)
stojko22 Posted August 24, 2017 Author Posted August 24, 2017 3 hours ago, Floops said: Something like this should work $file = FileOpen("test.ini") ; open file $i = 0 Do $i += 1 $bb = FileReadLine($file, $i) $iError = @error If StringInStr($bb, "Blode") Then ConsoleWrite("Substring found in line: " & $i & " | Text: " & $bb & @CRLF) Until $iError = -1 FileClose($file) I try this but works slow, it found result in first few lines fast, but i have almost million lines and this way need very much time to find a string.
AspirinJunkie Posted August 24, 2017 Posted August 24, 2017 it's because of the use of the line number parameter in filereadline. This leads to reiteration from file beginning every time the function is called. Remove the second parameter and it should run significantly faster: $file = FileOpen("test.ini") ; open file $i = 0 Do $i += 1 $bb = FileReadLine($file) If @error Then ExitLoop If StringInStr($bb, "Blode") Then ConsoleWrite("Substring found in line: " & $i & " | Text: " & $bb & @CRLF) Until False FileClose($file) Floops and stojko22 2
stojko22 Posted August 24, 2017 Author Posted August 24, 2017 2 minutes ago, AspirinJunkie said: it's because of the use of the line number parameter in filereadline. This leads to reiteration from file beginning every time the function is called. Remove the second parameter and it should run significantly faster: $file = FileOpen("test.ini") ; open file $i = 0 Do $i += 1 $bb = FileReadLine($file) If @error Then ExitLoop If StringInStr($bb, "Blode") Then ConsoleWrite("Substring found in line: " & $i & " | Text: " & $bb & @CRLF) Until False FileClose($file) Thanks, this works now like a charm
Floops Posted August 24, 2017 Posted August 24, 2017 14 minutes ago, AspirinJunkie said: it's because of the use of the line number parameter in filereadline. This leads to reiteration from file beginning every time the function is called. Damn I never knew of this until now. I should really pay more attention to the help files..
rootx Posted August 24, 2017 Posted August 24, 2017 i'm trying to read a big ini file so ini read don't work for me Why??? Autoit have a Function to do it and work as well, Use IniReadSectionNames or IniReadSection and use a loop to find your value. stojko22 1
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