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
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
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
if you want only numbers from string as long, then try this:
longValue = Long.parseLong("3e317188a00577".replaceAll("\\D+",""), 10);
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);
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);