Skip to content

Instantly share code, notes, and snippets.

@ooltcloud
Created February 8, 2016 14:24
Show Gist options
  • Save ooltcloud/6dd2f8492b7309aabcef to your computer and use it in GitHub Desktop.
Save ooltcloud/6dd2f8492b7309aabcef to your computer and use it in GitHub Desktop.
[VB.NET] 接頭辞付き 16進数文字列 → 整数変換
Function ToDec32(source As String) As Integer
' 0x?? , &hxx , $xx は 16進数とする
Dim h1 = Regex.Match(source, "(?i)^(?<prefix>0x|&h|\$)(?<body>.*)$")
If h1.Groups("prefix").Value <> "" Then
Return Convert.ToInt32(h1.Groups("body").Value, 16)
End If
' ??h は 16進数とする
Dim h2 = Regex.Match(source, "(?i)^(?<body>.*)(?<suffix>h)$")
If h2.Groups("suffix").Value <> "" Then
Return Convert.ToInt32(h2.Groups("body").Value, 16)
End If
' それ以外は 10進数 とする
Return Convert.ToInt32(source, 10)
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment