-4

My string is in "abcd123ef" format. I want it to convert in long format like in variable b. I tried many ways but got exception as 'input string is not in correct format'

Ways I tried are shown below:

1)

var a = "ABCD123Ef";
long b = convert.int64(a);

2)

var a = 'ABCD123Ef';
long b = parse.int64(a);

3)

long b = convert.int64("ABCD123Ef");
MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111
Akki Bhogte
  • 43
  • 1
  • 7
  • you mean input is hexadecimal? if so, see http://stackoverflow.com/questions/98559/how-to-parse-hex-values-into-a-uint – slawekwin Jan 20 '16 at 08:15
  • Are you trying to convert hex values? – David Pilkington Jan 20 '16 at 08:16
  • What do you mean by _long format_ exactly? Can you please be more specific about your problem? – Soner Gönül Jan 20 '16 at 08:17
  • Its not hexaecimal string... – Akki Bhogte Jan 20 '16 at 08:18
  • then how do you wish to convert it into long? by skipping all non-digit characters? or skipping until you find a first digit? you need to be more specific – slawekwin Jan 20 '16 at 08:22
  • I saw letter 'f' in lowercase but other letters are in uppercase. Look like it is in base64 format? – tdat00 Jan 20 '16 at 08:22
  • @AkkiBhogte - "Its not hexaecimal string..." - well, then what is it? You need to give us more information. Do you know, what the expected `long` value should be? - Please note that `"ABCD123Ef"` (or `"abcd123ef"`) is a `string`, **not** a `long`. – Corak Jan 20 '16 at 08:44

1 Answers1

2

If that is a hex value you can convert like this

var b = Convert.ToInt64 (a, 16);
David Pilkington
  • 13,528
  • 3
  • 41
  • 73