I have alphanumeric value = 106bd87f9386b63b. I want to convert this value into integer in c# and store the converted value into database. Is there any possibilities to convert it.
-
obviously "1 183 277 369 562 412 603" is too big for int – Selvin Jan 28 '19 at 11:19
-
3long number = long.Parse("106bd87f9386b63b", System.Globalization.NumberStyles.HexNumber); – jdweng Jan 28 '19 at 11:20
-
3If this is an encrypted block, as you've tagged, maybe you want to store this as a binary or varbinary column in your database instead? – Rup Jan 28 '19 at 11:22
-
3I guess you'd need to know how the value was encoded. Perhaps it is hex. – David Heffernan Jan 28 '19 at 12:22
2 Answers
Did you try to use this:
the strLong is a declared variable. and see this for your reference: https://learn.microsoft.com/en-us/dotnet/api/system.globalization.numberstyles?view=netframework-4.7.2
long.Parse(strLong, System.Globalization.NumberStyles.HexNumber);

- 367
- 2
- 9
You can do it with multiple methods choose one which is suitable to you
Method 1:
If you want to do it with Regex Here is Example helpful in Detail
C# Regular Expression to match letters, numbers and underscore
Here is also a useful and detailed link
Find and extract a number from a string
Other Methods:
You can also use Char.IsNumber('your character here')
here is Doc link of Microsoft
https://learn.microsoft.com/en-us/dotnet/api/system.char.isnumber?view=netframework-4.7.2
For the above method you have to split your string into characters and then check if it is character or not using Char.isNumber()
Method .
Instead of all these you can also split this and make a function and match ASCII values and detect weather it is a number of not .
What ever method you use just detect number or not and concatinate it into a string and then at the end convert this string into a number using Convert class provided by Microsoft . Here is the detailed link of conversion
How can I convert String to Int?

- 770
- 9
- 21