-4

How to convert the exponent value into equivalent .Net Datatype value. Does anyone know how to convert numeric + alphabetical string into long or int?

Example of a string : 3e317188a00577
tereško
  • 58,060
  • 25
  • 98
  • 150

4 Answers4

0

Maybe you want to extract digits only to create a long? You could use Char.IsDigit and LINQ:

Char[] digitsOnly = "3e317188a00577".Where(Char.IsDigit).ToArray();
if(digitsOnly.Length > 0)
{
    long result;
    if (long.TryParse(new string(digitsOnly), out result))
    {
        Console.Write("Successfully parsed to: " + result);
    }
}

Result: Successfully parsed to: 331718800577

If you instead want to parse it from hexadecimal to int/long:

long result = long.Parse("3e317188a00577", System.Globalization.NumberStyles.HexNumber);

Result: 17505812249314679

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • Thanks everyone for your replies! I got some inspiration thanks to all of you. Tim Schmelter your solution worked. Thanks again! – user3189577 Jan 13 '14 at 14:28
0

if you want only numbers from string as long, then try this:

longValue = Long.parseLong("3e317188a00577".replaceAll("\\D+",""), 10);
Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
0

The string you gave us looks like a hex value to me. In that case you can convert it to an int/long like this:

string numberAsHex = "3e317188a00577";
long numberAsInt = long.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
Tobi
  • 5,499
  • 3
  • 31
  • 47
0

Here is a similar question: Convert numbers with exponential notation from string to double or decimal

The way to do it is :

String myString = "3e317188a00577";
Double myDouble = double.Parse(myString, CultureInfo.InvariantCulture);
Community
  • 1
  • 1
Ahmad
  • 12,336
  • 6
  • 48
  • 88