From 9a2a37f2fc1d024031e6462d563cbd1316a915e5 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Wed, 9 Dec 2015 21:11:49 +0100 Subject: [PATCH] Misc --- ArchiSteamFarm/Utilities.cs | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index 5ccee56c1..24f264a96 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -22,23 +22,11 @@ */ -using System; -using System.Globalization; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace ArchiSteamFarm { internal static class Utilities { - private static readonly Random Random = new Random(); - - internal static int RandomNumber(int min, int max) { - return Random.Next(min, max + 1); - } - - internal static byte RandomDice() { - return (byte) RandomNumber(1, 6); - } - internal static async Task SleepAsync(int miliseconds) { await Task.Delay(miliseconds).ConfigureAwait(false); } @@ -48,16 +36,25 @@ namespace ArchiSteamFarm { return 0; } - string resultString; - try { - Regex regexObj = new Regex(@"[^\d]"); - resultString = regexObj.Replace(inputString, ""); - } catch (ArgumentException e) { - Logging.LogGenericException("Utilities", e); + string resultString = OnlyNumbersString(inputString); + if (string.IsNullOrEmpty(resultString)) { return 0; } - return ulong.Parse(resultString, CultureInfo.InvariantCulture); + ulong result; + if (!ulong.TryParse(resultString, out result)) { + return 0; + } + + return result; + } + + internal static string OnlyNumbersString(string text) { + if (string.IsNullOrEmpty(text)) { + return null; + } + + return Regex.Replace(text, @"[^\d]", ""); } } }