public static bool TryParseDevSecFromElapsedTimeString(string timeStr, out float sec) { sec = 0f; MatchCollection matchCollections = Regex.Matches(timeStr, "(?<number>(?:[0-9]+,)*[0-9]+)\\s*(?<units>[a-zA-Z]+)"); if (matchCollections.Count == 0) { return(false); } Match item = matchCollections[0]; if (!item.Groups[0].Success) { return(false); } Group group = item.Groups["number"]; Group item1 = item.Groups["units"]; if (!group.Success || !item1.Success) { return(false); } string value = group.Value; string str = item1.Value; if (!float.TryParse(value, out sec)) { return(false); } str = TimeUtils.ParseTimeUnitsStr(str); if (str == "min") { sec *= 60f; } else if (str == "hour") { sec *= 3600f; } return(true); }
public static bool TryParseDevSecFromElapsedTimeString(string timeStr, out float sec) { sec = 0f; MatchCollection matchCollection = Regex.Matches(timeStr, "(?<number>(?:[0-9]+,)*[0-9]+)\\s*(?<units>[a-zA-Z]+)"); if (matchCollection.get_Count() == 0) { return(false); } Match match = matchCollection.get_Item(0); if (!match.get_Groups().get_Item(0).get_Success()) { return(false); } Group group = match.get_Groups().get_Item("number"); Group group2 = match.get_Groups().get_Item("units"); if (!group.get_Success() || !group2.get_Success()) { return(false); } string value = group.get_Value(); string text = group2.get_Value(); if (!float.TryParse(value, ref sec)) { return(false); } text = TimeUtils.ParseTimeUnitsStr(text); if (text == "min") { sec *= 60f; } else if (text == "hour") { sec *= 3600f; } return(true); }