ok so im trying to port over some horrible code into C# but I am not sure exactly how to convert something like tihs:
Hex$(someInputString)
what would this be in C#?
Printable View
ok so im trying to port over some horrible code into C# but I am not sure exactly how to convert something like tihs:
Hex$(someInputString)
what would this be in C#?
you need to add a reference to Microsoft.VisualBasic, then:
Microsoft.VisualBasic.Conversion.Hex(number)
Paul's answer will guarantee the same result under all conditions since it is the same function being called.
If you want the equivalent without using the Microsoft.VisualBasic assembly, then use:
Code:Convert.ToString(someInputString, 16).ToUpper()
Thanks - yes exactly, do NOT want to add any references to VB assembly. :)
He could always translate it to Hex when converting it to a string in 1 move:The vb code for this is the same too: C# convert integer to hex and back again - Stack Overflowvb Code:
Dim Numb As Integer = 255 MessageBox.Show(Numb.ToString("X"))
yeh, I have that for some areas of the code so thats great. but when we have a string input which needs to be converted using the Hex$ in VB6, there is no equiv in C#:
ok so the problem is.... there is no overload for string and an int. but the input data is a string.
Convert.ToString(aStringHere, 16).ToUpper() - will not work
Sometimes you have to be creative to get around these limitations:
Code:System.Convert.ToString(System.Convert.ToInt32(aStringHere), 16).ToUpper()