Since that's a filename use the Path
class. Then you can use LINQ:
string fileName = "propimage22997_1.jpg";
string fileNameOnly = Path.GetFileNameWithoutExtension(fileName);
string token = fileNameOnly.Remove(fileNameOnly.LastIndexOf('_'));
string number = new string(token.SkipWhile(Char.IsLetter).ToArray()); //22997
or by skipping characters that are not digits:
number = new string(token.SkipWhile(c=> !Char.IsDigit(c)).ToArray());
If you need it as int
instead of string
use int.TryParse
(if the format can be invalid) or int.Parse
:
int num = int.Parse(number);