Why not just use the substring method? It's much simpler and easier to understand.
Or are there some restrictions that you haven't clearly explained? (hint hint)
My larger point is that
you should get in the habit of clearly explaining what you need to do. An example is always great, but it doesn't define the problem. Given your description, there is no reason that substring(5,9) wouldn't work (assuming I have my indexes correct).
If the number of digits can vary, you should include that in your problem description.
Just my 2cents
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors