-2

Please help me to write Regular expression on C# for getting Int64 value from string:

"NumberLong("634461051992965873")"

my string includes NumberLong part;

so as result must be 634461051992965873

Thank you!)))

Edward83
  • 6,664
  • 14
  • 74
  • 102

3 Answers3

3
string Temp = "Hax00r L33t";
string Output = Regex.Replace(Temp, "[^0-9]", "");
long num = long.Parse(Output);
RiaD
  • 46,822
  • 11
  • 79
  • 123
  • thank you! but it is not what I need))) I have string "NumberLong("634461051992965873")" and from this string I want to cut integer number;) – Edward83 Jul 13 '11 at 09:16
  • this should be Int64.Parse(text) – luketorjussen Jul 13 '11 at 09:17
  • 1
    @RiaD Ok, you reduced the length of the string. But in the OP's case, `int.Parse` won't work for reasons you should know. ;-) – Alex R. Jul 13 '11 at 09:17
  • @Alex R:, yes, you are right. @Edward83:http://stackoverflow.com/questions/844461/return-only-digits-0-9-from-a-string – RiaD Jul 13 '11 at 09:19
1

long.Parse("634461051992965873") does the job, but you could check long.TryParse too.

kͩeͣmͮpͥ ͩ
  • 7,783
  • 26
  • 40
1
String txt = "634461051992965873";
int nbr;

if(Int64.TryParse(txt, out nbr)) {
    // text can be converted to Integer
}
mastaH
  • 1,234
  • 3
  • 15
  • 30