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
Use this regular expression:
\d+$
var result = Regex.Match(input, @"\d+$").Value;
or using Stack
, probably more efficient:
var stack = new Stack();
for (var i = input.Length - 1; i >= 0; i--)
{
if (!char.IsNumber(input[i]))
{
break;
}
stack.Push(input[i]);
}
var result = new string(stack.ToArray());