Jump to content
Sign in to follow this  
Hyflex

StringRegExp to get time in miliseconds

Recommended Posts

Hyflex

Basically, I have a counter which counts down and i'm trying to get the time left in milliseconds...

Potential string formats:
Updates in: x hours xx minutes
Updates in: x hours xx minutes

Updates in: xx minutes xx seconds

Updates in: xx minutes xx seconds

Updates in: xx seconds

Updates in: x seconds

I've been trying a few things but none are working :/

$sResults = StringRegExp("Updates In: 22 hours, 13 minutes",'<b>Updates In:(.*)</b>',3)
$sSingleResult = $sResults[0]

If StringRegExp($sSingleResult, "hours") Then
ConsoleWrite(StringRegExp($sSingleResult, "(.*?)hours") & @CRLF)
$hours = True
EndIf
If StringRegExp($sSingleResult, "minutes") Then
ConsoleWrite(StringRegExp($sSingleResult, "minutes") & @CRLF)
$minutes = True
EndIf
If StringRegExp($sSingleResult, "(.*?) seconds") Then
ConsoleWrite(StringRegExp($sSingleResult, "(.*?)seconds") & @CRLF)
$seconds = True
EndIf
 
If StringMid($sSingleResult, 4, 5) = "hours" Then
$HoursIntoMiliseconds = StringMid($sSingleResult, 2, 1) * 3600000
$MinutesIntoMiliSeconds= StringMid($sSingleResult, 11, 2) * 60000
$TotalTime = $HoursIntoMiliseconds + $MinutesIntoMiliSeconds
Else
$MinutesIntoMiliSeconds = StringMid($sSingleResult, 2, 2) * 60000
EndIf
Edited by Hyflex

Share this post


Link to post
Share on other sites
jdelaney

try this out:

$string = "Updates in: 12 hours 12 minutes"

$array = StringRegExp($string, "(\d+)\s(\w+)", 4)

$iMilli = 0
For $i = 0 To UBound($array)-1
    $aTemp = $array[$i]
    Switch $aTemp[2]
        Case "hours"
            $iAddition = $aTemp[1]*(60*60*1000)
        Case "minutes"
            $iAddition = $aTemp[1]*(60*1000)
        Case "seconds"
            $iAddition = $aTemp[1]*(1000)
        Case Else
            MsgBox(1,1,"this one is not a covered 'Case'...add it in, and re-run=[" & $aTemp[2] & "].")
            $iAddition = 0
    EndSwitch
    $iMilli += $iAddition
Next

ConsoleWrite($iMilli & @CRLF)
Edited 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.

Share this post


Link to post
Share on other sites
Hyflex

Works beautifully, I don't quite understand how you achieved that...

Could you explain how that was done, it's something to do with the regexp I assume. 

Edited by Hyflex

Share this post


Link to post
Share on other sites
jdelaney

just looking for digits followed by letters.  Each grouping found is returned into it's own array (that's the option 4 on stringregexp)...then i loop through those returned groups, switch out based on the string, multiply, and add onto a variable.

Edit: I just added a fail checker as well...

Edited 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.

Share this post


Link to post
Share on other sites
guinness

There is also this site, which is a cheat sheet for regular expressions.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.