Skip to content

Commit feb42b4

Browse files
committed
fix to HexToInt to allow # and 0x at the beginning
1 parent 5a9e0c9 commit feb42b4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Code/MethodSystem/Methods/NumberMethods/HexToIntMethod.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class HexToIntMethod : ReturningMethod<NumberValue>, ICanError, IAddition
1515
{
1616
public override string Description => "Parses a hexadecimal number back to a number value";
1717

18-
public string AdditionalDescription => "Do not include the '#' symbol at the start of the text.";
18+
public string AdditionalDescription => "The hex number can start (but doesn't have to) with 0x or #";
1919

2020
public string[] ErrorReasons =>
2121
[
@@ -29,8 +29,16 @@ public class HexToIntMethod : ReturningMethod<NumberValue>, ICanError, IAddition
2929

3030
public override void Execute()
3131
{
32+
var hex = Args.GetText("hex number");
33+
34+
if (hex.StartsWith("0x"))
35+
hex = hex.Substring(2);
36+
37+
if (hex.StartsWith("#"))
38+
hex = hex.Substring(1);
39+
3240
ReturnValue = int.TryParse(
33-
Args.GetText("hex number"),
41+
hex,
3442
NumberStyles.HexNumber,
3543
NumberFormatInfo.InvariantInfo,
3644
out var result)

0 commit comments

Comments
 (0)