|
-
Aug 27th, 2012, 05:42 PM
#1
Thread Starter
PowerPoster
Hex$ - equivilent in C#?
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#?
-
Aug 27th, 2012, 05:52 PM
#2
Re: Hex$ - equivilent in C#?
you need to add a reference to Microsoft.VisualBasic, then:
Microsoft.VisualBasic.Conversion.Hex(number)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 27th, 2012, 07:28 PM
#3
Re: Hex$ - equivilent in C#?
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()
-
Aug 27th, 2012, 07:32 PM
#4
Thread Starter
PowerPoster
Re: Hex$ - equivilent in C#?
Thanks - yes exactly, do NOT want to add any references to VB assembly.
-
Aug 28th, 2012, 09:49 AM
#5
Re: Hex$ - equivilent in C#?
He could always translate it to Hex when converting it to a string in 1 move:
vb Code:
Dim Numb As Integer = 255
MessageBox.Show(Numb.ToString("X"))
The vb code for this is the same too: C# convert integer to hex and back again - Stack Overflow
-
Aug 28th, 2012, 11:35 AM
#6
Thread Starter
PowerPoster
Re: Hex$ - equivilent in C#?
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
-
Aug 28th, 2012, 11:41 AM
#7
Re: Hex$ - equivilent in C#?
Sometimes you have to be creative to get around these limitations:
Code:
System.Convert.ToString(System.Convert.ToInt32(aStringHere), 16).ToUpper()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|