From a6cb6900eca9a6071e4bbc969175c17f8bcc5536 Mon Sep 17 00:00:00 2001 From: haven1433 Date: Wed, 2 Aug 2023 23:10:18 -0500 Subject: [PATCH] TryParseHex should be able to work with 0x prefix --- src/HexManiac.Core/ViewModels/Theme.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/HexManiac.Core/ViewModels/Theme.cs b/src/HexManiac.Core/ViewModels/Theme.cs index 9c9f3293..8862a196 100644 --- a/src/HexManiac.Core/ViewModels/Theme.cs +++ b/src/HexManiac.Core/ViewModels/Theme.cs @@ -486,7 +486,11 @@ namespace HavenSoft.HexManiac.Core.ViewModels { return $"#{red:X2}{green:X2}{blue:X2}"; } - public static bool TryParseHex(this string hex, out int result) => int.TryParse(hex, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out result); + public static bool TryParseHex(this string hex, out int result) { + hex = hex.Trim(); + if (hex.StartsWith("0x")) hex = hex.Substring(2); + return int.TryParse(hex, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out result); + } public static (byte, byte, byte) ToRgb(this (double hue, double sat, double bright) hsb) => Theme.FromHSB(hsb.hue, hsb.sat, hsb.bright);