How to get time from string. sometime time in min and sometime in hrs

Below is the string format and this is not fixed i mean it can be anything containg time.

drive time 2.5 hrs @$40/hr = $100 tolls $4.44 EV charging $14.28 + 10% field nation surcharge

I want to get 2.5 from string

sometime this would be in mins also

1 Like


Hope this expression in an assign activity helps you

Cheers @Puneet_Singh1


You can try below expression in assign activity

extractedTime = System.Text.RegularExpressions.Regex.Match(yourString, “\b\d+(.\d+)? (hrs|mins)\b”).Value

This will extract the time duration (e.g., “2.5 hrs” or “30 mins”) from the string and store it in the extractedTime variable.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.