_Func Posted June 6, 2023 Posted June 6, 2023 Hello everyone, I'm a new user of Autoit and my first post is with the Number() function. I have a text file with differents values A;2 A;2.78 A;"3.9" A;"3.11" A;"3.11" A;7.9 A;N/A A;N/A A;N/A A;7.95 A;8.04 A;8.10 A;8.22 A;8.15 A;8.15 A;8.15 A;9.6 A;9.44 A;"9.59" A;11 A;14 A;15 A;15.6 A;N/A A;15.88 I tested the IsNumber() function but it doesn't work with quotes "". If I use Number() and after IsNumber(), N/A return 1. I don't understand...
Moderators JLogan3o13 Posted June 6, 2023 Moderators Posted June 6, 2023 Welcome to the forum @_Func. Can you please post the code you're using? There are, as with most languages, innumerable ways to skin the proverbial cat; seeing how you are going about this process will help us help you. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
_Func Posted June 6, 2023 Author Posted June 6, 2023 $file = @DesktopDir & "\Data.txt" $hFileOpen = FileOpen($file, 0) If $hFileOpen = -1 Then MsgBox(16, "Erreur", "Impossible d'ouvrir le fichier.") Exit EndIf While True Local $line = FileReadLine($hFileOpen) If @error = -1 Then ExitLoop $result = StringTrimLeft($line, 2) If IsNumber(Number($result)) Then ;~ If IsFloat($result) Then ConsoleWrite("$result :" & $result & @LF) EndIf WEnd FileClose($hFileOpen)
Solution Nine Posted June 6, 2023 Solution Posted June 6, 2023 #include <Array.au3> Local $aList = FileReadToArray("Test5.txt"), $aTemp _ArrayDisplay($aList) For $i = 0 to UBound ($aList) - 1 $aTemp = StringRegExp($aList[$i], "A;\""*(\d+\.*\d*)", 1) $aList[$i] = IsArray($aTemp) ? Number($aTemp[0]) : 0 Next _ArrayDisplay($aList) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
_Func Posted June 7, 2023 Author Posted June 7, 2023 I hadn't thought of using StringRegExp() and FileReadToArray() I don't understant the line with ? and : but, I will read the help file. Thank you
bogQ Posted June 7, 2023 Posted June 7, 2023 @_Func ? : are a shorter way for inline if then else $aList[$i] = IsArray($aTemp) ? Number($aTemp[0]) : 0 is ; something similar to this $aList[$i] = somefunc() Func somefunc() If IsArray($aTemp) Then return Number($aTemp[0]) return 0 EndFunc https://www.autoitscript.com/autoit3/docs/keywords/Ternary.htm TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.
mistersquirrle Posted June 7, 2023 Posted June 7, 2023 Here's something to keep in mind regarding data types and comparing them (or even checking if they are a specific type): https://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm#:~:text=Comparing different datatypes Another thing to look at is: https://www.autoitscript.com/autoit3/docs/functions/VarGetType.htm Maybe not entirely useful here, but it's along the same lines and is important to keep in mind. _Func 1 We ought not to misbehave, but we should look as though we could.
mikell Posted June 7, 2023 Posted June 7, 2023 Not sure that using Number() is necessary while \d is used in StringRegExp ... #Include <Array.au3> $res = StringRegExp(FileRead("Data.txt"), '(\d+(?:\.\d+)?)', 3) _ArrayDisplay($res)
Nine Posted June 7, 2023 Posted June 7, 2023 Well SRE retracts string, if you truly want a number as the variable (ex. for further sort) then it is recommended. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
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