amdogelover Posted December 12, 2016 Share Posted December 12, 2016 (edited) Hello, I'm trying to copy some game data from an output file but I'm having trouble with whitespaces. I've checked by manually deleting the whitespace/tabs and it works. What I'm trying to copy from the source file: Raw Benchmark Statistics for 1 run: Benchmark Statistics (Run No. 1): Min FPS: 46.4 <- THIS Max FPS: 80.8 Average FPS: 60.0 <- THIS Num Frames: 1471 <- THIS As you can see, there are whitespaces before, if I remove them my code works. My code looks like this: $tempAverageFpsVal = StringRegExp($fromSourceRead, 'Average FPS:(.*?)' & @CRLF, 1) I've tried with more or less everything in the documentation, \h, \s, +, etc, nothing works. Example: '(\s+)Average FPS:(.*?)' '(\t+)Average FPS:(.*?)' What am I doing wrong and how can I solve this? Thank you for the help. Edited December 12, 2016 by amdogelover Link to comment Share on other sites More sharing options...
mikell Posted December 12, 2016 Share Posted December 12, 2016 Try this StringRegExp($fromSourceRead, 'Average FPS:\s*(\S+)', 1) amdogelover 1 Link to comment Share on other sites More sharing options...
amdogelover Posted December 12, 2016 Author Share Posted December 12, 2016 4 minutes ago, mikell said: Try this StringRegExp($fromSourceRead, 'Average FPS:\s*(\S+)', 1) Hello mikell and thanks for the fast reply, unfortunately it didn't work, at the next line where I strip the whitespaces (StringStripWS) around the variable I get: ==> Subscript used a non-accessible variable And when I do a ConsoleWrite the saved value is 0. Link to comment Share on other sites More sharing options...
mikell Posted December 12, 2016 Share Posted December 12, 2016 StringRegExp(..., ..., 1) returns an array And my code strips the WS around the result Please try it on the text you posted in post #1 #Include <Array.au3> $txt = "Raw Benchmark Statistics for 1 run:" & @crlf & _ @crlf & _ " Benchmark Statistics (Run No. 1):" & @crlf & _ " Min FPS: 46.4 <- THIS" & @crlf & _ " Max FPS: 80.8" & @crlf & _ " Average FPS: 60.0 <- THIS" & @crlf & _ " Num Frames: 1471 <- THIS" Msgbox(0,"", $txt) ;$txt = FileRead("1.txt") $res = StringRegExp($txt, 'Average FPS:\s*(\S+)', 1) _ArrayDisplay($res) amdogelover 1 Link to comment Share on other sites More sharing options...
amdogelover Posted December 12, 2016 Author Share Posted December 12, 2016 21 minutes ago, mikell said: StringRegExp(..., ..., 1) returns an array And my code strips the WS around the result Please try it on the text you posted in post #1 #Include <Array.au3> $txt = "Raw Benchmark Statistics for 1 run:" & @crlf & _ @crlf & _ " Benchmark Statistics (Run No. 1):" & @crlf & _ " Min FPS: 46.4 <- THIS" & @crlf & _ " Max FPS: 80.8" & @crlf & _ " Average FPS: 60.0 <- THIS" & @crlf & _ " Num Frames: 1471 <- THIS" Msgbox(0,"", $txt) ;$txt = FileRead("1.txt") $res = StringRegExp($txt, 'Average FPS:\s*(\S+)', 1) _ArrayDisplay($res) You are correct, it seems that there is something else that is wrong. Your code works by the way! The problem lies with FileRead or the files themselves. When I display the FileRead-variable it shows this: If I edit 1 line in the .txt-file and save it, it works. The rest of my code looks like this, surely it can't be something here: $tempRead = _FileListToArray(@MyDocumentsDir & "\path\", "*X_2*") _ArrayDisplay($tempRead) $fromSourceRead = FileRead(@MyDocumentsDir & "\path\" & $tempRead[3]) Msgbox(0,"", $fromSourceRead) For $i = 1 To UBound($tempRead) - 1 ConsoleWrite("i: " & $i & " " & $tempRead[$i] & @CRLF) ConsoleWrite(@MyDocumentsDir & "\path\" & $tempRead[$i]& @CRLF) Next $tempAverageFpsVal2 = StringRegExp($fromSourceRead, 'Average FPS:\s*(\S+)', 1) $tempMinimumFpsVal2 = StringRegExp($fromSourceRead, 'Min FPS:\s*(\S+)', 1) $tempFramesFpsVal = StringRegExp($fromSourceRead, 'Num Frames:\s*(\S+)', 1) _ArrayDisplay($tempAverageFpsVal2) _ArrayDisplay($tempMinimumFpsVal2) _ArrayDisplay($tempFramesFpsVal) Link to comment Share on other sites More sharing options...
mikell Posted December 12, 2016 Share Posted December 12, 2016 I don't know how and where the files are but you could try something like this $tempRead = _FileListToArray(@MyDocumentsDir & "\path\", "*X_2*", $FLTA_FILES, true) _ArrayDisplay($tempRead) ; $fromSourceRead = FileRead($tempRead[3]) ; Msgbox(0,"", $fromSourceRead) For $i = 1 To $tempRead[0] ConsoleWrite("i: " & $i & " " & $tempRead[$i] & @CRLF) $fromSourceRead = FileRead($tempRead[$i]) $tempAverageFpsVal2 = StringRegExp($fromSourceRead, 'Average FPS:\s*(\S+)', 1) $tempMinimumFpsVal2 = StringRegExp($fromSourceRead, 'Min FPS:\s*(\S+)', 1) $tempFramesFpsVal = StringRegExp($fromSourceRead, 'Num Frames:\s*(\S+)', 1) _ArrayDisplay($tempAverageFpsVal2) _ArrayDisplay($tempMinimumFpsVal2) _ArrayDisplay($tempFramesFpsVal) Next amdogelover 1 Link to comment Share on other sites More sharing options...
amdogelover Posted December 12, 2016 Author Share Posted December 12, 2016 (edited) 10 hours ago, mikell said: I don't know how and where the files are but you could try something like this $tempRead = _FileListToArray(@MyDocumentsDir & "\path\", "*X_2*", $FLTA_FILES, true) _ArrayDisplay($tempRead) ; $fromSourceRead = FileRead($tempRead[3]) ; Msgbox(0,"", $fromSourceRead) For $i = 1 To $tempRead[0] ConsoleWrite("i: " & $i & " " & $tempRead[$i] & @CRLF) $fromSourceRead = FileRead($tempRead[$i]) $tempAverageFpsVal2 = StringRegExp($fromSourceRead, 'Average FPS:\s*(\S+)', 1) $tempMinimumFpsVal2 = StringRegExp($fromSourceRead, 'Min FPS:\s*(\S+)', 1) $tempFramesFpsVal = StringRegExp($fromSourceRead, 'Num Frames:\s*(\S+)', 1) _ArrayDisplay($tempAverageFpsVal2) _ArrayDisplay($tempMinimumFpsVal2) _ArrayDisplay($tempFramesFpsVal) Next Sorry for the late reply mikell, had to fix some bugs unrelated to this. Your code works very good, thanks for the new _FileListToArray, but the issue with the file still persists. Your code is working in every sense, but I found that the output files that I'm reading from has a blank line at the top (line 1 is empty) which makes the file bad for some reason. If I remove this line manually, AutoIT can fetch the strings properly, else it won't work. I'll see if I can work around this, if not I'll be back! EDIT: Oh god it worked I'm crying of joy! $fromSourceOpen = FileOpen($tempRead[2], $FO_ANSI) $fromSourceRead = FileRead($fromSourceOpen) Fixed it! Thank you very much @mikell for the help, I can't thank you enough! Edited December 12, 2016 by amdogelover Link to comment Share on other sites More sharing options...
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