Search code examples
vb.netstringhexdata-integrity

How to know if the output is "String" or "Hex"?


I've asked this question that allows me to convert the corresponding string to it's equivalent hex and the second answer seems working.

My question is how do I know if the outputted value is really Hex without using a machine that can only understand Hex?

For example:

Input: D7

Correct Output is: D7 (This is correct if it is Hex, if it is string then it is not correct)


Solution

  • Assuming there's no limitation on the length of the string to check:

    Dim _inputStr As String = "D7"
    Dim _isCorrectHex As Boolean = Text.RegularExpressions.Regex.Match(_inputStr, "^([0-9a-fA-F]+)$").Success