Probably over analysing this a little bit but how would stackoverflow suggest is the best way to return an integer that is contained at the end of a string.
Thus far I have considered using a simple loop, LINQ and regex but I'm curious what approaches I'll get from the community. Obviously this isn't a hard problem to solve but could have allot of variance in the solutions.
So to be more specific, how would you create a function to return an arbitrarily long integer/long that is appended at the end of an arbitrarily long string?
CPR123 => 123
ABCDEF123456 => 123456
Use this regular expression:
or using
Stack
, probably more efficient:should do it I think
Regex would be the easiest, as far as my experience.
This should match it. Just wrap that in a function.
A simple loop should probably beat any other solution in its simplicity and efficiency. And final returned string can be just copied once without usage of Stack, StringBuilder, string.Concat or other more complex string supporting functions.
Or it can be even returned back directly as int type:
Obligatory LINQ one-liner
Is it always in the format LettersNumbers?
In that case, this would work: