Skip to content

Commit

Permalink
Support hex syntax in IntegerType.FromString.
Browse files Browse the repository at this point in the history
  • Loading branch information
Esme Povirk committed Dec 1, 2020
1 parent ad68868 commit 609437d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Expand Up @@ -29,6 +29,7 @@
' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Imports System
Imports System.Globalization
Imports System.Runtime.InteropServices
Namespace Microsoft.VisualBasic.CompilerServices
<System.ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)> _
Expand Down Expand Up @@ -90,6 +91,10 @@ Namespace Microsoft.VisualBasic.CompilerServices
#End If

Try
If Value.TrimStart(Nothing).StartsWith("&H", StringComparison.CurrentCultureIgnoreCase) Then
Return Int32.Parse(Value.TrimStart(Nothing).Substring(2), NumberStyles.AllowHexSpecifier)
End If

#If TRACE Then
System.Console.WriteLine("TRACE:IntegerType.FromString:Value:" + Int32.Parse(Value).ToString())
#End If
Expand Down
Expand Up @@ -75,6 +75,16 @@ public void FromString2()
i = Microsoft.VisualBasic.CompilerServices.IntegerType.FromString(st);
}

[Test]
public void FromStringHex()
{
int i;
i = Microsoft.VisualBasic.CompilerServices.IntegerType.FromString("&H1aB");
Assert.AreEqual (0x1ab, i, "&H1aB");
i = Microsoft.VisualBasic.CompilerServices.IntegerType.FromString(" &H1");
Assert.AreEqual (1, i, " &H1");
}

#endregion

#region FromObject
Expand Down

0 comments on commit 609437d

Please sign in to comment.