Jump to content
Sign in to follow this  
MyEarth

IniRead value is string or not

Recommended Posts

MyEarth

Like tilte, i want to know if the value of a IniRead is a number ( 15 ) or a string ( 15a, or another word )

Seems easy but isn't, i have some problem with it :(

My script

IniWrite(@ScriptDir & "\myfile.ini", "section1", "key", "15a")
IniWrite(@ScriptDir & "\myfile.ini", "section2", "key", "15")

$section1 = IniRead(@ScriptDir & "\myfile.ini", "section1", "key", "NotFound")
$section2 = IniRead(@ScriptDir & "\myfile.ini", "section2", "key", "NotFound")

If IsNumber($section1) Then ConsoleWrite("$section1 is a string" & @CRLF)
If IsNumber($section2) Then ConsoleWrite("$section2 is a string" & @CRLF)
If Not IsNumber($section1) Then ConsoleWrite("$section1 is a number" & @CRLF)
If Not IsNumber($section2) Then ConsoleWrite("$section2 is a number" & @CRLF)

Where is my error? Thank you guys

Edited by MyEarth

Share this post


Link to post
Share on other sites
guinness

StringIsInt?


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
MyEarth

Thanks for the suggestion, searching for StringIsInt i have found also a function:

IniWrite(@ScriptDir & "\myfile.ini", "section1", "key", "15a")
IniWrite(@ScriptDir & "\myfile.ini", "section2", "key", "15")

$section1 = IniRead(@ScriptDir & "\myfile.ini", "section1", "key", "NotFound")
$section2 = IniRead(@ScriptDir & "\myfile.ini", "section2", "key", "NotFound")

If Not StringIsInt($section1) Then ConsoleWrite("$section1 is a string" & @CRLF)
If Not StringIsInt($section2) Then ConsoleWrite("$section2 is a string" & @CRLF)
If StringIsInt($section1) Then ConsoleWrite("$section1 is a number" & @CRLF)
If StringIsInt($section2) Then ConsoleWrite("$section2 is a number" & @CRLF)
ConsoleWrite("$section1 is a number? " & _StringIsNumber($section1) & @CRLF)
ConsoleWrite("$section2 is a number? " & _StringIsNumber($section2) & @CRLF)

Func _StringIsNumber($v_num)
    Return (Int(StringIsInt($v_num)) + Int(StringIsFloat($v_num)) > 0)
EndFunc

It's a little complex to me for understand what he do lol

Both give me correct resul but what is better to use, only StringIsInt or _StringIsNumber by SmOke_N? Thanks again

Edited by MyEarth

Share this post


Link to post
Share on other sites
guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
MyEarth

Mmm StringRegExp isn't a little "slow"? I absolutely follow what you say and what is better to use, is only a question

Share this post


Link to post
Share on other sites
guinness

StringRegExp() slow? How did you come to that conclusion?


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
MyEarth

For what i have read around :D

Or maybe was StringRegExpReplace? Anyway i can considered this solved, thanks guinness

Share this post


Link to post
Share on other sites
jchd

Urban legend?


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
Chimp

Urban legend?

 

maybe not a legend...

Time spent by StringRegExp:    44.8638025223876

Time spent by StringIsInt:     23.4686252023651

$start = TimerInit()
For $i = 1 To 1000
    $x = StringIsNum('Example')
    $x = StringIsNum('123456')
    $x = StringIsNum('Example & 123456')
Next
ConsoleWrite("Time spent by StringRegExp: " & @TAB & TimerDiff($start) & @CRLF)

$start = TimerInit()
For $i = 1 To 1000
    $x = _StringIsNumber('Example')
    $x = _StringIsNumber('123456')
    $x = _StringIsNumber('Example & 123456')
Next
ConsoleWrite("Time spent by StringIsInt: " & @TAB & TimerDiff($start) & @CRLF)

Func StringIsNum($sString)
    Return StringRegExp($sString, "^([0-9]*(\.[0-9]+){1}|[0-9]+(\.[0-9]*){0,1})$") = 1
EndFunc   ;==>StringIsNum

Func _StringIsNumber($v_num)
    Return (Int(StringIsInt($v_num)) + Int(StringIsFloat($v_num)) > 0)
EndFunc   ;==>_StringIsNumber

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
jchd

Ah yes, that's the release. I'm a bit ahead with the beta which speeds up things a bit.

But the devil is always where you don't expect it. Let's see:

$start = TimerInit()
For $i = 1 To 250000
    $x = StringIsInt('Example')
    $x = StringIsInt('123456')
    $x = StringIsInt('123456789.0123456789')
    $x = StringIsInt('Example & 123456')
Next
ConsoleWrite("Time spent by StringIsInt: " & @TAB & TimerDiff($start) & @CRLF)

$start = TimerInit()
For $i = 1 To 250000
    $x = _StringIsIntRE('Example')
    $x = _StringIsIntRE('123456')
    $x = _StringIsIntRE('123456789.0123456789')
    $x = _StringIsIntRE('Example & 123456')
Next
ConsoleWrite("Time spent by StringIsIntRE: " & @TAB & TimerDiff($start) & @CRLF)

$start = TimerInit()
For $i = 1 To 250000
    $x = _StringIsNumber('Example')
    $x = _StringIsNumber('123456')
    $x = _StringIsNumber('123456789.0123456789')
    $x = _StringIsNumber('Example & 123456')
Next
ConsoleWrite("Time spent by _StringIsNumber: " & @TAB & TimerDiff($start) & @CRLF)

$start = TimerInit()
For $i = 1 To 250000
    $x = _StringIsNumRE('Example')
    $x = _StringIsNumRE('123456')
    $x = _StringIsNumRE('123456789.0123456789')
    $x = _StringIsNumRE('Example & 123456')
Next
ConsoleWrite("Time spent by _StringIsNumRE: " & @TAB & TimerDiff($start) & @CRLF)

$start = TimerInit()
For $i = 1 To 250000
    $x = _StringIsNumberOR('Example')
    $x = _StringIsNumberOR('123456')
    $x = _StringIsNumberOR('123456789.0123456789')
    $x = _StringIsNumberOR('Example & 123456')
Next
ConsoleWrite("Time spent by StringIsNumberOR: " & @TAB & TimerDiff($start) & @CRLF)

Func _StringIsIntRE($sString)
    Return StringRegExp($sString, "^[+-]?\d+")
EndFunc   ;==>_StringIsNumRE

Func _StringIsNumRE($sString)
    Return StringRegExp($sString, "^[+-]?\d*(\.\d+)?$")
EndFunc   ;==>_StringIsNumRE

Func _StringIsNumber($v_num)
    Return (Int(StringIsInt($v_num)) + Int(StringIsFloat($v_num))) > 0
EndFunc   ;==>_StringIsNumber

Func _StringIsNumberOR($v_num)
    Return StringIsInt($v_num) OR StringIsFloat($v_num)
EndFunc   ;==>_StringIsNumberOR

Results on my slow PC:

Time spent by StringIsInt:  1969.09167226561
Time spent by StringIsIntRE:    13523.2643394621
Time spent by _StringIsNumber:  13095.1144628717
Time spent by _StringIsNumRE:   15741.8785767465
Time spent by StringIsNumberOR:     9943.98072939438

So yes, unsurprisingly a regexp is marginally slower than a combination of core functins (the contrary would be big news) but the major saving is on combining more efficiently the core functions with OR. Of course the built-in StringIsInt puts everything else in the dust.

OTOH, these timing apply to one million invokations. I question how many conversions of .INI section names is the OP going to perform in the real world?


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
sahsanu

 

maybe not a legend...

Time spent by StringRegExp:    44.8638025223876

Time spent by StringIsInt:     23.4686252023651

 

Switch code blocks (first StringIsInt and then RegExp) and change the regular expression used and you won't notice too much difference (StrinisDigit is still a litlle faster but not so much) ^_^

For $a = 1 To 10
    ConsoleWrite("Round " & $a & @CRLF)

    $start = TimerInit()
    For $i = 1 To 1000
        $x = _StringIsNumber('Example')
        $x = _StringIsNumber('123456')
        $x = _StringIsNumber('Example & 123456')
    Next
    ConsoleWrite("Time spent by StringIsInt: " & @TAB & TimerDiff($start) & @CRLF)

    $start = TimerInit()
    For $i = 1 To 1000
        $x = StringIsNum('Example')
        $x = StringIsNum('123456')
        $x = StringIsNum('Example & 123456')
    Next
    ConsoleWrite("Time spent by StringRegExp: " & @TAB & TimerDiff($start) & @CRLF)

Next

Func StringIsNum($sString)
    ;Return StringRegExp($sString, "^([0-9]*(\.[0-9]+){1}|[0-9]+(\.[0-9]*){0,1})$") = 1
    Return StringRegExp($sString, "^[0-9]{1,}$") = 1
EndFunc   ;==>StringIsNum

Func _StringIsNumber($v_num)
    Return (Int(StringIsInt($v_num)) + Int(StringIsFloat($v_num)) > 0)
EndFunc   ;==>_StringIsNumber
Round 1
Time spent by StringIsInt:  12.700604734011
Time spent by StringRegExp: 18.2434182681315
Round 2
Time spent by StringIsInt:  11.3463059746374
Time spent by StringRegExp: 16.4625913453782
Round 3
Time spent by StringIsInt:  10.6993296652185
Time spent by StringRegExp: 13.9567897002685
Round 4
Time spent by StringIsInt:  15.7663528804198
Time spent by StringRegExp: 12.5593865547978
Round 5
Time spent by StringIsInt:  11.1923617385764
Time spent by StringRegExp: 13.2289413521723
Round 6
Time spent by StringIsInt:  10.6439097402365
Time spent by StringRegExp: 12.5166926866635
Round 7
Time spent by StringIsInt:  10.5527747524885
Time spent by StringRegExp: 12.5056087016672
Round 8
Time spent by StringIsInt:  11.7297297519199
Time spent by StringRegExp: 11.6221740456586
Round 9
Time spent by StringIsInt:  10.2218972744481
Time spent by StringRegExp: 12.2502665287874
Round 10
Time spent by StringIsInt:  11.1894881128366
Time spent by StringRegExp: 11.8019809133778

Cheers,

sahsanu

Share this post


Link to post
Share on other sites
jchd

That's a bit like comparing oranges and bananas.

The regexp you use doesn't allow for signed integers nor floats.


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
sahsanu

That's a bit like comparing oranges and bananas.

The regexp you use doesn't allow for signed integers nor floats.

 

Both are fruits. Anyway, It was just an example to demonstrate that a different regex in "a concrete example" can change the time to process the same script giving the same results.

Share this post


Link to post
Share on other sites
Chimp

Both are fruits. Anyway, It was just an example to demonstrate that a different regex in "a concrete example" can change the time to process the same script giving the same results.

 

as noted by jchd your simplified regexp doesn't allow for signed integers nor floats,

anyway, despite this, simplifing also the StringIs* function as well, as highlighted in the jchd's tests,  is again evident that StringRegExp is slower than built-in StringIs* functions

Time spent by StringIs*:        16.8649926177768

Time spent by StringRegExp:     29.1319148104019

if you make just one call to this function the difference is irrelevant, but in >cases like this can make the difference. :)

For $a = 1 To 10
    ConsoleWrite("Round " & $a & @CRLF)
    $start = TimerInit()
    For $i = 1 To 1000
        $x = _StringIsNumber('Example')
        $x = _StringIsNumber('123456')
        $x = _StringIsNumber('Example & 123456')
    Next
    ConsoleWrite("Time spent by StringIs*: " & @TAB & TimerDiff($start) & @CRLF)

    $start = TimerInit()
    For $i = 1 To 1000
        $x = StringIsNum('Example')
        $x = StringIsNum('123456')
        $x = StringIsNum('Example & 123456')
    Next
    ConsoleWrite("Time spent by StringRegExp: " & @TAB & TimerDiff($start) & @CRLF)
Next

Func StringIsNum($sString)
    ;Return StringRegExp($sString, "^([0-9]*(\.[0-9]+){1}|[0-9]+(\.[0-9]*){0,1})$") = 1
    Return StringRegExp($sString, "^[0-9]{1,}$") = 1
EndFunc   ;==>StringIsNum

Func _StringIsNumber($v_num)
    ; Return (Int(StringIsInt($v_num)) + Int(StringIsFloat($v_num)) > 0)
    Return StringIsInt($v_num) Or StringIsFloat($v_num)
EndFunc   ;==>_StringIsNumber

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
sahsanu

 

as noted by jchd your simplified regexp doesn't allow for signed integers nor floats,

anyway, despite this, simplifing also the StringIs* function as well, as highlighted in the jchd's tests,  is again evident that StringRegExp is slower than built-in StringIs* functions

Time spent by StringIs*:        16.8649926177768

Time spent by StringRegExp:     29.1319148104019

if you make just one call to this function the difference is irrelevant, but in >cases like this can make the difference. :)

 

I never said otherwise :), I totally agree that StringIs* functions are faster than RegExp and, as you commented, it is evident in a slow computer or when the amount of data to be processed is huge.

Cheers,

sahsanu

Share this post


Link to post
Share on other sites
guinness

jchd did you test with the beta?

v3.3.8.1
Time spent by StringIsInt:  949.094973967549
Time spent by StringIsIntRE:    11248.9134408781
Time spent by _StringIsNumber:  9120.54696496617
Time spent by _StringIsNumRE:   12995.7006864434
Time spent by StringIsNumberOR:     6762.12615621035

v.3.3.9.20
Time spent by StringIsInt:  936.100743532945
Time spent by StringIsIntRE:    6268.7745490022
Time spent by _StringIsNumber:  5735.45633527998
Time spent by _StringIsNumRE:   7363.73678581833
Time spent by StringIsNumberOR:     4083.51939578906
Everyone else (but jchd)

If you're worried about "speed" then why are you reading from an INI file?


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Chimp

with autoit v.3.3.9.20, the overall processing is faster, but it seems that the relationship between the two variables is always approximately 1.8 times faster with StringIsNum () versus StringRegExp ().
If data to be processed are mandatory in an INI file, what else can you do besides read from the INI file?
:think:


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
jchd

Granted but how many such section names are going to be processed in practice and how much delay difference is it going to make to the user?

Hence "slow" is very relative to how things are used in the real world.

When people expect to process Gb of data (like in another thread) then indeed the fastest way is important (but AutoIt is certainly not suited to process gigabytes of data in the most efficient way). But in many common applications, several times few µs will be un-noticeable to humans.


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
Chimp

from a practical point of view I agree :)


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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  

×